开发者

Unable to connect to Sql Server Express database

I installed Sql Server Express 2008 R2, and created a database file in Sql Server management Studio. Now From Visual Studio 2008 I try to connect, but it fails with error:

Unable to open the physical file "C:.....mdf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)". An attempt to attach an auto-named database for file C:....mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

...This is first time I use Express. I only used Sql Compact Edition before. Are there some settings here I need to figure out? It's not a duplicate name of other connection, and I have closed management studio completely. Still this error. What a开发者_如何学编程m I missing..?

If there are some settings, please give a little detail how I access them, as I'm not used to dealing with databases.


SQL CE is a file based database - SQL Express isn't.

It is a SQL Server - you can add it using the Server Explorer in Visual Studio.

The instance name is normally .\SqlExpress.


I faced the same issue today, and guess what daemon tools was the reason for this problem, so if you have installed daemon tools uninstall it and then try again. Hope it solves your problem too.


You do not want to be connecting using the mdf. What you want to do is Open a SqlClient.SqlConnection and then using the SqlClient.SqlCommand execute queries on the database, and then read the information using the SqlClient.DataReader, just like you would with A SqlCE database.

If you are trying to add it to the Server Explorer you just need to connect to the database just like you would in SSMS (Management Studio) and then you can use it in your project.


If you created a database in SQL Server, you probably have it attached. In Visual Studio you cannot access this database as a file. You have to access it as an attached database (i.e. by its name).

Generally you can use database in files as well in Express edition. If you for some reason want to use file directly, then go to Management studio, right click on your database and detach it. Then you can connect to it from Visual Studio on file basis.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜