开发者

"Cannot open user default database" error with "User Instance=True"

I have a desktop application that uses Sql user instancing. This is my connection string:

"Data Source=.\SqlExpress;
AttachDbFilename=C:\path\file.mdf;
Integrated Security=True;
User Instance=True;
Connect Timeout=100;"

My application creates this DB, downloads a load of data into it from a web service and then does a lot of actions with it.

The problem comes when I attempt to re-open the connection. I get a SqlException:

"Cannot open user default database.开发者_JS百科 Login failed.

Login failed for user 'myDomain\myusername'."

This error makes no sense in this context - I have no default database. I'm logging in to an instance created just for the current application, running separately from SqlExpress.

There's no other way to connect to this DB. If I start the SqlExpress service and connect to the default instance it won't be visible. It only exists for this application.

The file on disk is locked by the SqlExpress instance service running under the application. if I stop the app and restart it the connection works first time, but fails on re-opening. If I just stop the app I can delete the .mdf files and begin again, but it still crashes when I re-open the connection.

As my app started the instance running as me my current user should have access to every DB in the instance.

This doesn't happen for other users of the same code, which suggests that it's a SQL config issue.

Does anyone have any idea what causes this and how to work around it?


If this is still a problem, take a look at the points in my answer here - specifically the link to the MSDN blog regarding user instances:

"Cannot open user default database. Login failed." after installing SQL Server Management Studio Express

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜