2

我有一个本机 C++ 应用程序,我在其中尝试使用 ADO 连接到 localdb 实例。手动启动我的实例后,我可以运行sqllocaldb info v11.0并查看数据库实例正在运行。

我的代码如下。

ADO::_ConnectionPtr spConnection (__uuidof (ADO::Connection));
spConnection->Open (L"Provider=SQLNCLI11;Server=(localdb)\\v11.0;Integrated Security=true", L"", L"", 0);

错误代码为 DB_E_ERRORSOCCURRED (0x80040e21),错误消息为多步 OLE DB 操作生成错误。检查每个 OLE DB 状态值(如果可用)。没有做任何工作。

我能够使用 SQL Server Management Studio 成功连接到数据库,并且在连接字符串中使用和不使用提供程序以及指定初始目录都进行了尝试。

4

2 回答 2

1

我发现了我的问题。安全性必须设置sspi为如下所示。

ADO::_ConnectionPtr spConnection (__uuidof (ADO::Connection));
spConnection->Open (L"Provider=SQLNCLI11;Server=(localdb)\\v11.0;Integrated Security=SSPI", L"", L"", 0);
于 2012-07-10T14:31:45.733 回答
0

ADO connection object has an Error collection that holds the list oft error that has occured so far. You can take a look at these error to see what's wrong. Usually two things can go wrong while connecting to SQL Server. 1.Login Failed. 2.SQL Server is not configured so that you can connect to it remotely. Since you are trying to connect to a local server it can hardly be the second reason. As you might now there are two different type of authentication when it comes to SQL Server:Windows and SQL Server.You can use one of therm if each of them is set in your SQL Server options or both of them if the mixed mode is selected. According to your connection string you are using windows mode authentication therefor you should be logged in using a windows user that can login to SQL Server.If that's not the case with your SQL Server then you should provide a SQL user credentials in your connection string. Anyway check the Error collection of connection object as see if there's anything else is wrong with your local db.

于 2012-07-09T21:52:39.113 回答