App.Config Problems...

N

Nisha

Hi,

I want to store my SQL connection string in an App.Config file. So I did the
following:

On my form I put in a SQLConnection Object called SqlConnection1.
In the properties of SqlConnection1.. under Dynamic Properties--> Advanced

I checked the connection property which by default gets mapped to
sqlconnection1.connectionstring.

In my app.config file the key is automatically added i.e
"sqlconnection1.connectionstring" & the value is my connectionstring.

In the load event of my form I have put in the following lines of code, so I
can retrieve the value of the connectionstring.

Dim ConfigReader As System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader

Dim connectstr As String

connectstr = CType(ConfigReader.GetValue("sqlConnection.ConnectionString",
GetType(System.String)), String)

I expect to see connectstr containing the value of my connectionstring.
However it is always "".



Can someone tell me what I am doing wrong here?

Thanks in advance.

...Nisha
 
M

Miha Markic

Hi Nisha,

Connection string will be automatically assigned to
sqlconnection1.connectionstring.
However, if this is not your goal, you might retrieve it using by reading
from ConfigurationSettings.AppSettings["sqlconnection1.connectionstring"]
 
N

Nisha

Thanks Bill.

I had a look at the example on website... and it is no different from what I
am doing. Fairly straight forward actually.

Thanks for your help. I will need to look at this once again... must be
something silly I am doing.

...Nisha
 

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

Top