使用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;
        }