开发者

login failed connecting to SQL Server with AttachDbFilename and User Instance

I am developing ASP.NET 2.0 application using SQL Express 2005. I have attached my database with the application.

The Connection string:

 <add name="WCMIRConnectionString"  providerName=开发者_如何学JAVA"System.Data.SqlClient"
  connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;\App_Data\WCMIR.mdf&quot;;Integrated Security=True;Trusted_Connection=no;User Instance=True" />

When trying to connect the following error appears :

Cannot open database "dp-name" requested by the login. The login failed. Login failed for user 'Machine\useID'.

How can this error be resolved?


First I think the connection string should be with |App_Data| not \App_Data\
Second Make sure that this user has permission on this folder and on this DB


You shouldn't need the AttachDbFileName if your database is already attached, but you should include InitialCatalog to indicate which database you would like to connect to.


Problem Solved Connection string must be like :

Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|DB.MDF;" + "Integrated Security=True;User Instance=True";


Just try to use "|" instead of backslash in your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜