开发者

Java MSAccess DSN Less

开发者 https://www.devze.com 2023-03-11 17:51 出处:网络
So the problem is that I want to make a connection to a msaccess database that has password every time you open it.

So the problem is that I want to make a connection to a msaccess database that has password every time you open it.

  • The password works if I directly open the access file.
  • I can make the connection if I remove the开发者_如何学Go password, which means my code works if there is no password involve
  • The password was set using Set database Password in the database tools
  • MS Access 2007(but i used the .mdb)

Here's the code

String dbFile = "db.mdb";
String connectionString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
String driverID = ";DriverID=22;READONLY=true;pwd=qwer}";
if (CONNECTION == null || CONNECTION.isClosed()) {
   dbURL = connectionString + dbFile.trim() + driverID;
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   CONNECTION = DriverManager.getConnection(dbURL);
}

----------------------------------------------
Error Code : java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid password.
----------------------------------------------

I already tried adding parameters to the get connection but it did not work. Please Help :)


There are 2 types of passwords for MS Access database files:

  1. user passwords
  2. database password

With a user password, you supply the user name and password in the connection string.

;User Id=admin;Password=;

For a database password, you need a different identifier in the connection string to distinguish the password as a database password rather than a user password.

;Database Password=MyDbPassword;

Personally I don't use a database password. That feature doesn't offer much in the way of security, so it seems like it's more trouble than it's worth.

Edit: I don't know if it's possible to supply a database password with an ODBC connection. All the connection examples I found used OLE DB when including a database password.

Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\somepath\\mydb.mdb;" & _
                 "Jet OLEDB:Database Password=MyDbPassword;", "admin", ""

Perhaps it could work to switch from the current Access ODBC driver to the Microsoft OLE DB Provider for ODBC. Or maybe with the current ODBC driver if you switch

Database Password=MyDbPassword;

to

Jet OLEDB:Database Password=MyDbPassword;

I don't know. But seems to me the database password is just getting in your way here. You already know you can connect if you remove the password from the database.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号