Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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();


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.
Posted

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?
 
Share this answer
 
Comments
boogac 1-Mar-13 3:14am    
this is not a solution,use have a question or comment button please
MuhammadUSman1 4-Mar-13 1:53am    
Any idea?
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>
 
Share this answer
 
Here is a link to check "how to make sqlconnection"

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900