今天练习ASP。NET和SQL SERVER的连接问题,SQL SERVER是安装在我本机的,但是,如果我把server写成
server = localhost,就会说数据库不存在或者拒绝访问,如果写成我自己的IP,就没有问题,不明白是为什么,代码记录下来:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string sqlStr;
sqlStr = "SELECT * FROM tblStudent";
SqlConnection myConn = new SqlConnection("server=localhost;uid=sa;pwd=sa;database=testStudent");
SqlDataAdapter myCmd = new SqlDataAdapter(sqlStr,myConn);
DataSet myDs = new DataSet();
myCmd.Fill(myDs);
DataView source = new DataView(myDs.Tables[0]);
DataGrid1.DataSource = source;
DataGrid1.DataBind();
}