简体   繁体   中英

Error trying to establish connection to SQL Server Express

I created a web site in Visual Studio 2012 that interacts with a SQL Server Express database table where the database was created beforehand with SQL Server 2008. I added the connection with the database to the site, and all of this worked fine.

Now I am doing exactly the same with a new website but now get the error message.

System.Data.SqlClient.SqlException (0x80131904): Login failed for user ''

The error happens as I am trying to make the connection and with my previous project everything was fine and still is, exactly the same connection string was used in both cases. From where does this exception come from all of a sudden?

try
{
    connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=Employee,Integrated Security=True;";

    using (conn = new SqlConnection(connectionString))
    {
        conn.Open();
       .....
    }
}

How can I resolve this?

you have invalid connection string, you have used , instead of ;

connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=Employee;Integrated Security=True;";
                                                                   // ^ here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM