当前位置:编程学习 > C#/ASP.NET >>

VS2005中连接SQL Server2000 连接字符串

vs2005中连接sql server2000 连接字符串

sqlconnection conn = new sqlconnection(sqlconn.connstring);
        string sqltext = "select * from loginuser where (username='" + name + "') and (" + "userpwd='" + pwd + "')";
        sqlcommand command = new sqlcommand(sqltext, conn);
        //try
        //{
            conn.open();
            //try to get the information and identification
            //try
            //{
                sqldatareader datareader = command.executereader();//sqldatareader doesn't have a constructor
                if (datareader.read() == true)
                {
                    response.redirect("modellist.asp教程x");
                }
                else
                {
                    response.redirect("logerr.aspx");
                }
            //}
            //catch (system.exception exception)
            //{
            //    response.redirect("syserr.aspx");
            //}
            conn.close();

        //}
        //catch (system.exception excetion1)
        //{
        //    response.redirect("opendatabaseerr.aspx");
        //}
  


  /*
  vs2005中连接sql server2000 连接字符串2009-11-05 22:54private static string connstring = "server=(local);database=webdevelop;uid=sa;pwd=sa";

这里的(local)还可以是localhost或者127.0.0.1

从这里可以看出,应该写服务器的地址,由于是本地运行,而且在iis中绑定了127.0.0.1这个地址,所以写localhost和127.0.0.1都可以。另外,(local)是sql server 2000 中的服务器对象,所以也是可以的。如果在iis中将此网站设为默认网站,而且绑定地址169.254.218.201,则还可以这样连接:

private static string connstring = "server=169.254.218.201;database=webdevelop;uid=sa;pwd=sa";

如果是数据库教程在远程服务器上运行,则此处应该写远程服务器的ip地址。

另外,打开和读取数据库 中数据时,很容易抛出异常,所以不要经常捕捉,否则会出错

补充:asp.net教程,基础入门
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,