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

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top