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="\App_Data\WCMIR.mdf";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.
精彩评论