Login failed while connecting to database

I created a WPF application with an MDF file. When I added the MDF file to my solutions folder, it automatically generated a connection string for me

     <add name="Connection"
    connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=C:\Users\Public\Desktop\MyDatabase.mdf;Integrated Security=True;"
    providerName="System.Data.SqlClient" />

      

I Deployed my application using SQL Server Compact ( as described here ). But when I run my application I get the exception

Unable to open database "C: \ Users \ Public \ Desktop \ MyDatabase.mdf" requested by login. Login failed.

Login failed for user "MY-PC \ NAME".

I am using Windows Authentication for my SQL Server

+3


source to share


1 answer


change your connection string like this:



<add name="Connection"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=C:\Users\Public\Desktop\MyDatabase.mdf;persist security info=True;Integrated Security=SSPI;"providerName="System.Data.SqlClient" />

      

+2


source







All Articles