简体   繁体   中英

Unable To Connect using Server Explorer

I'm in Visual Studio 2013, using SQL Server Express 2012, on Windows 7 OS.

With C# code, I CAN connect to the database and query. For example:

using (SqlConnection sqlConnection = new SqlConnection("server=MYSERVER\\SQLEXPRESS; Trusted_Connection=yes; database=MyDatabase; connection timeout=30"))
{

    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.CommandText = "SELECT count(*) FROM tblData";
                cmd.Connection = sqlConnection;
                sqlConnection.Open();
                int count = (int)cmd.ExecuteScalar();
                Console.WriteLine(count);  // I get the correct answer.
        }
}

That works. My problem is that if I use Server Explorer within Visual Studio, I cannot connect to the database via that route. In the Add Connection, MyServer does appear in the server dropdown, but the database dropdown is empty. When I click Test Connection or OK (leaving Database empty or entering MyDatabase), I get the error: Server was not found or was not accessible.

So I can connect via C# code, but not with Server Explorer. What am I missing?

Thanks.

You have a named instance ( SQLExpress ) of the SQL Server. In the connections window, try typing in the server name as:

MYSERVER\\SQLEXPRESS

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