我在 Visual Studio 2013 中,在 Windows 7 操作系统上使用 SQL Server Express 2012。
使用 C# 代码,我可以连接到数据库并进行查询。例如:
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.
}
}
这样可行。我的问题是,如果我在 Visual Studio 中使用服务器资源管理器,我无法通过该路由连接到数据库。在添加连接中,MyServer 确实出现在服务器下拉列表中,但数据库下拉列表为空。当我单击测试连接或确定(将数据库留空或输入 MyDatabase)时,我收到错误消息:找不到服务器或无法访问。
所以我可以通过 C# 代码连接,但不能使用服务器资源管理器。我错过了什么?
谢谢。