日期:2014-05-18  浏览次数:20538 次

VS2005与SQL2005连接问题
我在webconfig中设置   connectionString= "Data   Source=localhost;Initial   Catalog=Vote;Integrated   Security=True "   providerName= "System.Data.SqlClient ",提示无法连接数据库;
设置成     connectionString= "Data   Source=计算机名\\SQLEXPRESS;Initial   Catalog=Vote;Integrated   Security=True "   providerName= "System.Data.SqlClient "提示“实例失败。  
说明:   执行当前   Web   请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。  

异常详细信息:   System.InvalidOperationException:   实例失败。

源错误:  

执行当前   Web   请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。    


请教各位高手:原因出在哪?要怎么连接呢?


------解决方案--------------------
<connectionStrings>
<add name= "pubsConnectionString1 " connectionString= "Data Source=BB\SQLExpress;Initial Catalog=pubs;Integrated Security=True "
providerName= "System.Data.SqlClient " />
</connectionStrings>

你检查一下你的数据库名是否正确
第一种应该已经接近成功了
第二种,在web.Config中 \\ 是没有必要的
------解决方案--------------------
这里就不能用集成windows身份了,得改成:
<add name= "pubsConnectionString1 " connectionString= "Data Source=BB\SQLExpress;Initial Catalog=pubs;uid=sa;pwd=sa "
providerName= "System.Data.SqlClient " />