我是新手。。现在需要一个用c#且连接SQl2000的源代码!!
谢谢指导!!
请发到信箱[email protected]

解决方案 »

  1.   

        System.Data.SqlClient.SqlConnection DB_Connect = null;
        System.Data.SqlClient.SqlCommand DB_Command = null;
        System.Data.SqlClient.SqlDataReader DB_Reader = null;
        string SQL_Command = string.Empty;
                string _DB_ConnStr = "workstation id=" + 服务器名称或IP + ";" + "packet size=4096;user id=" + 用户名称 + ";" + "data source=" + ODBC名称 + ";" + "persist security info=True;initial catalog=" + 数据库名称 + ";password=" + 密码 + ";Pooling=yes"; 
                try
                {
                    DB_Connect = new System.Data.SqlClient.SqlConnection();
                    DB_Command = new System.Data.SqlClient.SqlCommand();
                    if (DB_Connect.State == ConnectionState.Closed)
                    {
                         DB_Connect.ConnectionString = _DB_ConnStr;
                         DB_Connect.Open();
                    }
                    DB_Command.Connection = DB_Connect;                SQL_Command = "SELECT name FROM sysobjects WHERE Lower(xtype)=\'u\'";                DB_Command.CommandText = SQL_Command;
                    DB_Command.CommandType = CommandType.Text;
                    DB_Command.Prepare();
                    DB_Reader = DB_Command.ExecuteReader();                while (DB_Reader.Read())
                    {
                        if (!Convert.IsDBNull(DB_Reader["name"]))
                        {
                            //......;
                        }
                    }                return true;
                }
                catch (SqlException ex)
                {
                    return false;
                }
        finally
        {
    if (DB_Reader != null)
    {
       if (! DB_Reader.IsClosed)
       {
    DB_Reader.Close();
       }
    }
    if (DB_Connect.State == ConnectionState.Open)
    {
       DB_Connect.Close();
       DB_Connect.Dispose();
    }
    DB_Connect = null;
    DB_Command = null;    }
      

  2.   

    SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();
    sb.UserID = "sa";
    sb.Password = "***********************";
    sb.DataSource = "(local)";
    sb.InitialCatalog = "master";SqlConnection conn = new SqlConnection( sb.ConnectionString );
      

  3.   

    看来楼主联登陆CSDN都懒得蹬。