I have created a database in SQL but when I want to access it by C# but the compiler can't access and open database.
the error is :
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Cannot open database "Restaurant" requested by the login. The login failed.
Login failed for user 'Milad0007\Milad.H'
Additional information: Cannot open database "Restaurant" requested by the login. The login failed.
Login failed for user 'Milad0007\Milad.H'
Please guide me to solve it.


Abhay ShankerRank #375 · 6.7K reputationPosted Jun 29, 2015, 6:26 PM EDT
RakeshRank #397 · 6.3K reputationPosted Jun 29, 2015, 7:36 PM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 29, 2015, 8:03 PM EDT
Nilesh JadavRank #109 · 20.3K reputationPosted Jun 29, 2015, 9:00 PM EDT
Try like this:
Go to your database.mdf - - > Press f4 - -> Connection string Copy the whole Connection string. it looks like this :
just change it to like this:
You need to remove the path and make it short like:
C:\Users\Nilesh\Documents\Visual Studio 2010\WebSites\WebSite13\App_Data -- > Remove this
And add this "|DataDirectory|".
After
Hope this works !!
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 29, 2015, 9:01 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 29, 2015, 9:01 PM EDT
Vignesh ManiRank #98 · 22.1K reputationPosted Jun 30, 2015, 12:11 PM EDT
Vignesh ManiRank #98 · 22.1K reputationPosted Jun 30, 2015, 12:19 PM EDT
Vignesh ManiRank #98 · 22.1K reputationPosted Jun 29, 2015, 8:36 PM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jun 30, 2015, 12:00 PM EDT
Vignesh ManiRank #98 · 22.1K reputationPosted Jun 30, 2015, 12:05 PM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jun 30, 2015, 12:06 PM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jun 30, 2015, 12:13 PM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jun 30, 2015, 1:56 PM EDT