日期:2014-05-19  浏览次数:20858 次

最后40分````求解一个简单简单简单问题````
早上调试程序的时候出现如下问题:

    执行到   Conn.Open();时报错;   错误提示:System.NullReferenceException:   未将对象引用设置到对象的实例

代码如下:

SqlConnection   Conn   =   new   SqlConnection();

Conn.ConnectionString   =   "data   source=127.0.0.1;persist   security   info=False;initial   catalog=flyhouse;user   id=sa;   password=;Max   Pool   Size=512 ";

Conn.Open();

堆栈跟踪:

   
[NullReferenceException:   未将对象引用设置到对象的实例。]
      LoadLibraryW(UInt16*   )   +0
      System.EnterpriseServices.Thunk.Security.Init()   +76
      System.EnterpriseServices.Thunk.Security.SuspendImpersonation()   +81
      System.EnterpriseServices.Platform.Initialize()   +503
      System.EnterpriseServices.ResourcePool..ctor(TransactionEndDelegate   cb)   +11
      System.Data.SqlClient.ConnectionPool..ctor(DefaultPoolControl   ctrl)   +797
      System.Data.SqlClient.PoolManager.FindOrCreatePool(DefaultPoolControl   ctrl)   +170
      System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString   options,   Boolean&   isInTransaction)   +358
      System.Data.SqlClient.SqlConnection.Open()   +384
      WebApplication3.WebForm1.Page_Load(Object   sender,   EventArgs   e)   in   f:\w文件备分\flyhouse\programe\webapplication3\webform1.aspx.cs:34
      System.Web.UI.Control.OnLoad(EventArgs   e)   +67
      System.Web.UI.Control.LoadRecursive()   +35
      System.Web.UI.Page.ProcessRequestMain()   +731

 


------解决方案--------------------
楼主的数据库呢?
写成这样不是更方便么
connectionString= "server=172.16.1.6;User ID=rrr;Password=rrr;database=rrr_portal;Provider = SQLOLEDB.1;Connection Reset=FALSE "
------解决方案--------------------
initial catalog=flyhouse;
是库吧?
------解决方案--------------------
数据库连接字符串有点问题=。=
------解决方案--------------------
楼主说的问题比较怪。。。
------解决方案--------------------
SQL 2000:
static string StrConn = "workstation id=202.134.127.77;data source=202.134.127.77;initial catalog=Yellowpage;user id=sa;password=grt2006 ";

SQL2005:
con = new SqlConnection(@ "Server=.\SQLExpress;Database=db_CMS;Persist Security Info=True;User ID=sa;Password=Masslong ");
------解决方案--------------------
楼主说的问题比较怪。。。

------解决方案--------------------
这字符串好像没问题,你sa的password为空吗?
------解决方案--------------------
try

"data source=127.0.0.1;persist security info= ' "+False+ " ';initial catalog= ' "+flyhouse+ " ';user id=sa; password=;Max Pool Size=512 ";

------解决方案--------------------
Max Pool Size=512
问题出在这,改大一点或者重启电脑
------解决方案--------------------