2

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.

user3052078
  • 487
  • 1
  • 8
  • 20

2 Answers2

0

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

Dgan
  • 10,077
  • 1
  • 29
  • 51
Anupam Sharma
  • 368
  • 3
  • 12
0

This is works for me

1. Data Source=(LocalDb)\v11.0;Initial Catalog=CSN;Integrated Security=SSPI;

The full version

2. <add name="DefaultConnection" 
   connectionString="Data Source=(LocalDb)\v11.0;
   Initial Catalog={catalog name};
   Integrated Security=SSPI;
   AttachDBFilename=|DataDirectory|\{database name}.mdf"        
   providerName="System.Data.SqlClient" />;

where {catalog name} is your database name and {database name} also your database name

Here you can find full list of connection strings

http://www.connectionstrings.com/sql-server-2012/

Dgan
  • 10,077
  • 1
  • 29
  • 51
genichm
  • 525
  • 7
  • 18