Problem while using Global Connection String

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
 
S

SV

Aaahhhh,

Its solved....I have changed strConn like below and its works

strConn =
ConfigurationManager.ConnectionStrings("Conn").ConnectionString

Thanks anyways.

SV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top