I still can't figure out .net 2.0 DB Connection Strings

D

Darrel

*sigh*...I have gotten no where with my .net 2.0 project. ;o)

I'm still stuck on db connection strings.

I have a connection string in my web config:

<appSettings>
<add key="DBConn" value="[my connection string]" />
</appSettings>

Then in my function, I try to get it. I've tried this:

Dim strConnect As String =
ConfigurationManager.ConnectionStrings("DBConn").ConnectionString()

as well as this:

Dim strConnect As String =
ConfigurationManager.ConnectionStrings("DBConn").toString()

to no avail.I keep getting an error on that line:
 
M

Marc Scheuner

*sigh*...I have gotten no where with my .net 2.0 project. ;o)
I'm still stuck on db connection strings.

I have a connection string in my web config:

<appSettings>
<add key="DBConn" value="[my connection string]" />
</appSettings>

Then in my function, I try to get it. I've tried this:

Dim strConnect As String =
ConfigurationManager.ConnectionStrings("DBConn").ConnectionString()

You need to put your connection strings into the <connectionStrings>
section - *NOT* the <appSettings> !

Marc
 
W

William Buchanan

<configuration>
<appSettings>
<add key="XXX" value="YYY" />
</appSettings>
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=MyData.mdf;Integrated
Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
......
 
D

Darrel

You need to put your connection strings into the <connectionStrings>
section - *NOT* the <appSettings> !

Aha! Thanks, Marc...that was staring right at me in the config file, too.
'doh!

-Darrel
 
D

Darrel

<configuration>
<appSettings>
<add key="XXX" value="YYY" />
</appSettings>
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=MyData.mdf;Integrated
Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>

THanks, william...that clarified things!

-Darrel
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top