C#的winform为什么与SQL Server2008 连不上,求高手指点
代码是:stringconnectionString="datasource=CNCHECNU2161F68/SQLEXPRESS;userid=sa;pwd=skf;d...
代码是:
string connectionString = "data source=CNCHECNU2161F68/SQLEXPRESS;user id=sa;pwd=skf;database=Data24;";
SqlConnection con=new SqlConnection();
con.ConnectionString = connectionString;
try
{
con.Open();
rtbMessage.Text="连接数据库"+con.Database+"成功。连接字符串如下:\n"+con.ConnectionString;
}
catch(Exception ex)
{
rtbMessage.Text=ex.Message;
}
finally
{
con.Close();
}
错误信息是:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 展开
string connectionString = "data source=CNCHECNU2161F68/SQLEXPRESS;user id=sa;pwd=skf;database=Data24;";
SqlConnection con=new SqlConnection();
con.ConnectionString = connectionString;
try
{
con.Open();
rtbMessage.Text="连接数据库"+con.Database+"成功。连接字符串如下:\n"+con.ConnectionString;
}
catch(Exception ex)
{
rtbMessage.Text=ex.Message;
}
finally
{
con.Close();
}
错误信息是:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 展开
4个回答
展开全部
CNCHECNU2161F68/SQLEXPRESS写错了,一般应为
CNCHECNU2161F68\\SQLEXPRESS
或者
(local)\\SQLEXPRESS
或者
.\\SQLEXPRESS
CNCHECNU2161F68\\SQLEXPRESS
或者
(local)\\SQLEXPRESS
或者
.\\SQLEXPRESS
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该是你的sqlserver 2008 关于是否能远程这个没打开。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是否启动了远程服务?
追问
远程服务如何启动?应该是配置好的,我用现有的软件连接名称为另外一个的数据库可以连接成功。
追答
SQL Server2008 2R的配置与SQL Server2005的配置相似的。你可以在网上查查相关资料。
你尝试改为下面:string connectionString = @"data source=.;user id=sa;pwd=skf;database=Data24;";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询