使用C#連接SQL 2000服务器时提示:[DBNETLIB][ConnectionOpen (Connect()).]SQL Server 不存在或拒絕存取。
连接字符串:"Provider=SQLOLEDB;Data Source=CE21;User ID=ALVDTest;Password=ALVDTest;Initial Catalog=ALVTest"必须要先与服务器建立连接后才能正常连接(net use \\ce21\share "test" /user:test)
alvdtest是数据库的用户名,权限是没有问题的,只是在连接前要多执行一步:net use \\ce21\share "test" /user:test
程序如下:
private bool ConnectDBSer()
{
if (conn.State == ConnectionState.Open) return true;
string connstr = string.Format(@"Provider=SQLOLEDB;Data Source={0};User ID={1};Password={2};Initial Catalog=ALVTest",servername,username,password);
conn.ConnectionString = connstr;
bool result = true;
try
{
conn.Open(); //--> 这里就提示错误了
result = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "连接数据库失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
result = false;
}
return result;
}
连接字符串:"Provider=SQLOLEDB;Data Source=CE21;User ID=ALVDTest;Password=ALVDTest;Initial Catalog=ALVTest"必须要先与服务器建立连接后才能正常连接(net use \\ce21\share "test" /user:test)
alvdtest是数据库的用户名,权限是没有问题的,只是在连接前要多执行一步:net use \\ce21\share "test" /user:test
程序如下:
private bool ConnectDBSer()
{
if (conn.State == ConnectionState.Open) return true;
string connstr = string.Format(@"Provider=SQLOLEDB;Data Source={0};User ID={1};Password={2};Initial Catalog=ALVTest",servername,username,password);
conn.ConnectionString = connstr;
bool result = true;
try
{
conn.Open(); //--> 这里就提示错误了
result = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "连接数据库失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
result = false;
}
return result;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货