S
SV
I am new to .Net. I am working on .Net 2005. I am defining connection
string in my web.config file as :
<configuration>
<connectionStrings>
<add name="Conn" connectionString="Data Source=xxx;Initial
Catalog=yyy;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
And I am using that String in my class to open connection as:
Public Sub OpenConnection()
sqlConn = New SqlConnection
sqlComd = New SqlCommand
sqlComd.Connection = sqlConn
strConn =
Configuration.ConfigurationManager.AppSettings("Conn").ToString()
sqlConn.ConnectionString = strConn
sqlConn.Open()
End Sub
But I am getting error “System.NullReferenceException was unhandled by
user code” and “Object reference not set to an instance of an object.”
Where I am wrong?
I tried the following syntax also:
strConn =
System.Configuration.ConfigurationManager.AppSettings("Conn").ToString()
But I am still getting same error.
Any help really appreciated.
Thanks,
SV
string in my web.config file as :
<configuration>
<connectionStrings>
<add name="Conn" connectionString="Data Source=xxx;Initial
Catalog=yyy;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
And I am using that String in my class to open connection as:
Public Sub OpenConnection()
sqlConn = New SqlConnection
sqlComd = New SqlCommand
sqlComd.Connection = sqlConn
strConn =
Configuration.ConfigurationManager.AppSettings("Conn").ToString()
sqlConn.ConnectionString = strConn
sqlConn.Open()
End Sub
But I am getting error “System.NullReferenceException was unhandled by
user code” and “Object reference not set to an instance of an object.”
Where I am wrong?
I tried the following syntax also:
strConn =
System.Configuration.ConfigurationManager.AppSettings("Conn").ToString()
But I am still getting same error.
Any help really appreciated.
Thanks,
SV