2
votes

I have a native C++ app within which I am trying to connect to a localdb instance using ADO. Having manually started my instance I can run sqllocaldb info v11.0 and see the database instance is running.

My code is as follows.

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

The error code is DB_E_ERRORSOCCURRED (0x80040e21) and the error message is Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

I am able to successfully connect to the database using SQL Server Management Studio and I've tried it both with and without the provider in the connection string as well as specifying an initial catalog.

2
Have you installed .NET 4.02 or higher on your local computer ? this is a prerequisite for using localdbSteve
I did install .NET 4.02 (from support.microsoft.com/kb/2544514) with no luck although I thought this was only required it get it to with with VS2010Stephen Nutt

2 Answers

1
votes

I found my issue. The security must be set to sspi as shown below.

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

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.