sqlconncection出错 [英] Error in sqlconncection

查看:149
本文介绍了sqlconncection出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数据库开发应用程序。

当他们尝试创建SqlConnection类的对象时,它会抛出异常。

Em尝试使用代码



Em developing an application using database.
when em trying to create an object of SqlConnection class it is throwing an exception.
Em trying following Code.

System.Data.SqlClient.SqlConnection objSqlCon = new System.Data.SqlClient.SqlConnection();





它抛出以下异常。

< b>'System.Data.SqlClient.SqlConnection'的类型初始值设定项引发异常。



我也试试

$ b





it is throwing following Exception.
The type initializer for ''System.Data.SqlClient.SqlConnection'' threw an exception.

I also try



System.Data.SqlClient.SqlConnection objSqlCon = new System.Data.SqlClient.SqlConnection("MyConnectionStringHere");





但它抛出同样的异常。





提前使用。



But it is throwing same Exception.


Thanx in advance.

推荐答案

连接字符串中没有问题。

连接字符串正常。但在两种情况下,使用/不带连接字符串都会抛出相同的异常。



为什么不用连接字符串创建对象?
Issue not in connection string.
Connection string is ok. but in both cases with/with out connection string it is throwing same exception.

why not it is creating object with out connection string?


有可能在web.config文件中,connectionstring命令不是为了与sql server建立连接.......检查web.config文件是否连接..







在web.config文件中,写下connectionstring如下:



< connectionStrings>

< add name =DBConnectionconnectionString =Server = localhost \\SQLExpress; Database = test; Integrated Security = TrueproviderName =System.Data.SqlClient/>

< / connectionStrings>
It may be possible that in web.config file, connectionstring command is not written to make connection with sql server....... Check web.config file whether connection is made or not..



In web.config file, write the connectionstring as below:

<connectionStrings>
<add name="DBConnection" connectionString="Server=localhost\\SQLExpress;Database=test;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>


这是一个检查如何进行sqlconnection的链接



http://msdn.microsoft.com/en-us/library/s4yys16a%28v=vs .71%29.aspx [ ^ ]
Here is a link to check "how to make sqlconnection"

http://msdn.microsoft.com/en-us/library/s4yys16a%28v=vs.71%29.aspx[^]


这篇关于sqlconncection出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆