Question

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.

Was it helpful?

Solution

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

MYSERVER\SQLEXPRESS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top