Search code examples
c#sql-serverdatabaselocal-database

sql local database connection


I am trying to open my local database in c# with this code :

SqlConnection c = new SqlConnection("Server = (LocalDB)\\v11.0 ;Integrated Security=True;Database =Informati;");
c.Open();

But i receive an error when he is trying to open it :

Cannot open database "Informati" requested by the login. The login failed.
Login failed for user 'AURELIAN121\Aurelian'.

I've tried to connect using

new SqlConnection("Server = (LocalDB)\v11.0 ;User id=AURELIAN121\Aurelian;Integrated Security=True;Database =Informati;");

but the error persist.


Solution

  • Your connection string is not correct : For local database u can use dot also, like

    SqlConnection c = new SqlConnection("Data Source=.;
    Integrated Security=True;Initial Catalog=Informati;");
    

    From error it seams that your local user does not have access permission on Sql server. U have to add create login first :http://www.reliasoft.com/support/rs40024.htm