连接数据库失败!
1、大家看看我这么写有问题吗?
2、2005和2003连接数据库的代码有区别吗?
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection myConn = new SqlConnection();
string strConn = "server=localhost;uid=sa;pwd=;database=pubs ";
myConn.ConnectionString = strConn;
myConn.Open();
Response.Write( " <script language= 'javascript '> alert ( '连接成功! ') </script> ");
myConn.Close();
}
catch
{
Response.Write( " <script language= 'javascript '> alert ( '连接失败! ') </script> ");
}
}
}
------解决方案--------------------应该没问题的 看看你pwd 是不是为空 ~ 或者 你的sql server 是什么方式注册的