标题:[求助]打开SQL连接的问题
取消只看楼主
jackrebel
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-4-21
 问题点数:0 回复次数:1 
[求助]打开SQL连接的问题

不能打开数据库连接,我新建个项目在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



这究竟是怎么回事啊?我前几天都能正常运行的东西~现在都出现了这个问题,高手帮忙解决下。不胜感激~!

搜索更多相关主题的帖子: SQL 数据库 con STRONG pubs 
2007-05-22 11:50
jackrebel
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-4-21
得分:0 
先谢谢版主,localhost和英文的点不是一样么?输入的那个点绝对是切换到英文输入法输入的.

不过问题是现在又能正常连接上了,不知怎么回事.重新启动了几次电脑.又行了.郁闷~~找不到原因.系统服务不正常?

没点安全感..........

在代码中打滚
2007-05-23 11:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-141453-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.056057 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved