Connection string format and SQL Server login error

This is my first "first code approach" with SQL Server 2012 Express.

I am trying to create a database but there is a problem with the connection string.

This is my connection string:

Data Source=AMBROGIO\SQLEXPRESS;Initial Catalog=TAP2014_15Project;Integrated Security=True;

      

This is the connection string that goes to my setup function:

Data Source=AMBROGIO\\SQLEXPRESS;Initial Catalog=TAP2014_15Project;Integrated Security=True;

      

With a double \\

after my PC name.

For a test, I tried to write something else as a connection string, and when debugging it comes up unchanged (obviously it throws an error).

Can anyone help me?

Thank.

Filippo


Hi, sorry if I answer just now. Yes, I used a debugger to see the line.

Now I have an error caused by my method:

 db.Database.CreateIfNotExists();

      

Mistake:

Exception:Thrown: "Cannot open database "TAP2014_15Project" requested by the            
login. The login failed.
Login failed for user 'AMBROGIO\Filippo'."       
(System.Data.SqlClient.SqlException)
A System.Data.SqlClient.SqlException was thrown: "Cannot open database  
"TAP2014_15Project" requested by the login. The login failed.
Login failed for user 'AMBROGIO\Filippo'."

      

+3


source to share


2 answers


Your config file should contain the following line:

<add name="ConnectionStringName"
     providerName="System.Data.SqlClient"
     connectionString="Data Source=AMBROGIO\SQLEXPRESS;Initial Catalog=TAP2014_15Project;Integrated Security=True" />

      

If you set up the connection string from C # code then:

connectionString = @"Data Source=AMBROGIO\SQLEXPRESS;Initial Catalog=TAP2014_15Project;Integrated Security=True";

      



Source example .

UPDATE

Regarding the login error question - the same problem exists. Check it out .

+2


source


The double backslash is an escape sequence that allows one backslash when included in a double-quoted delimited string. The backslash is used in many contexts to denote the start of a multi-character escape sequence to represent special or non-printable characters. Unfortunately, Microsoft also chose backslashes as the path separator in its early DOS operating systems. Therefore, to express the path separator in double quoted strings, you need to use a double backslash.



+1


source







All Articles