简体   繁体   English

我可以在Excel VBA中访问加密的SQL Server Compact数据库吗?

[英]Can I access an encrypted SQL Server Compact database in Excel VBA?

I want to access an encrypted SQL Server Compact Edition database via VBA. 我想通过VBA访问加密的SQL Server Compact Edition数据库。 I can access the database fine when it is not encrypted, but the code breaks when I try to use a password: 当未加密时,我可以很好地访问数据库,但是当我尝试使用密码时,代码会中断:

pConn.ConnectionString = "PROVIDER=Microsoft.SQLSERVER.CE.OLEDB.3.5;Password=[my_password];Data Source=" & SdfPath

I've been following the connection string example provided here for SQL Server Compact with a password: 我一直在遵循此处为SQL Server Compact提供的带有密码的连接字符串示例

Encryption enabled 启用加密

Use this connection string to enable encryption on the database. 使用此连接字符串在数据库上启用加密。

Data Source=MyData.sdf;Encrypt Database=True;Password=myPassword; 数据源= MyData.sdf;加密数据库= True;密码= myPassword; File Mode=shared read;Persist Security Info=False; 文件模式=共享读取;持久安全信息=否;

The Encrypt Database="True" pair is really not necessary as the presence of the Password-parameter itself turns on encryption for the connection. 实际上,不需要Encrypt Database =“ True”对,因为密码参数本身的存在会打开连接的加密。

But why doesn't this work in Excel VBA 2010? 但是,为什么这在Excel VBA 2010中不起作用?

Apparently, the connection string example in the site I was using is incorrect. 显然,我正在使用的站点中的连接字符串示例不正确。 I found the correct connection string example from Microsoft : 从Microsoft找到了正确的连接字符串示例

Using Microsoft ActiveX® Data Objects for Windows CE (ADOCE), Microsoft ActiveX Data Objects Extensions for Data Definition Language (DDL) and Security (ADOXCE), or the Replication object To create a password-protected database using the either the ADOCE or ADOXCE Catalog object, or the AddSubscription method of the SQL Server CE Replication ActiveX object, you must specify the provider-specific SSCE:Database Password connection property in the connection string. 使用Windows CE(ADOCE)的MicrosoftActiveX®数据对象,数据定义语言(DDL)和安全性(ADOXCE)的Microsoft ActiveX数据对象扩展或复制对象使用ADOCE或ADOXCE目录创建受密码保护的数据库对象或SQL Server CE Replication ActiveX对象的AddSubscription方法, 必须在连接字符串中指定提供程序特定的SSCE:Database Password连接属性 For example: 例如:

"Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0; data source=\\NorthWind.sdf; SSCE:Database Password=[myPassword] " “提供程序= Microsoft.SQLSERVER.OLEDB.CE.2.0;数据源= \\ NorthWind.sdf; SSCE:数据库密码= [myPassword]

And so now my code is: 所以现在我的代码是:

pConn.ConnectionString = "PROVIDER=Microsoft.SQLSERVER.CE.OLEDB.3.5;SSCE:Database Password=[my_password];Data Source=" & SdfPath

This worked perfectly for me. 这对我来说非常有效。

If you have SQL Server Compact 4.0 installed and use "Microsoft.SQLSERVER.CE.OLEDB.2.0" or "Microsoft.SQLSERVER.CE.OLEDB.3.5" as provider in connection string, you will get an error mentioning provider not found. 如果您已安装SQL Server Compact 4.0,并在连接字符串中使用“ Microsoft.SQLSERVER.CE.OLEDB.2.0”或“ Microsoft.SQLSERVER.CE.OLEDB.3.5”作为提供程序,则将出现错误,提示找不到提供程序。 Change connection string to reflect to "Microsoft.SQLSERVER.CE.OLEDB.4.0". 更改连接字符串以反映为“ Microsoft.SQLSERVER.CE.OLEDB.4.0”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM