不能打开数据库连接,我新建个项目在Page_Load事件里面写简单的两句都会出错
如:
SqlConnection con=new SqlConnection("server=.;database=pubs;uid=sa;pwd=sa");
con.Open();
sql服务已经开启
服务是本机,pubs数据库绝对有,用户名和密码都是sa,我能用它们登陆查询分析器.就是con.Open()提示错误!
错误如下:
Server Error in '/WebApplication1' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 26: // 在此处放置用户代码以初始化页面
Line 27: SqlConnection con=new SqlConnection("server=.;database=login;uid=sa;pwd=sa");
Line 28: con.Open();
Line 29: }
Line 30:
捕获的异常如下:
System.NullReferenceException: Object reference not set to an instance of an object. at LoadLibraryW(UInt16* ) at System.EnterpriseServices.Thunk.Security.Init() at System.EnterpriseServices.Thunk.Security.SuspendImpersonation() at System.EnterpriseServices.Platform.Initialize() at System.EnterpriseServices.ResourcePool..ctor(TransactionEndDelegate cb) at System.Data.SqlClient.ConnectionPool..ctor(DefaultPoolControl ctrl) at System.Data.SqlClient.PoolManager.FindOrCreatePool(DefaultPoolControl ctrl) at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) at System.Data.SqlClient.SqlConnection.Open() at WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication1\webform1.aspx.cs:line 30
这究竟是怎么回事啊?我前几天都能正常运行的东西~现在都出现了这个问题,高手帮忙解决下。不胜感激~!