473,383 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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

*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").C onnectionString()

as well as this:

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

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

--------------
Object reference not set to an instance of an object.
App_Web_0-ola1a7
--------------

What am I doing wrong?

-Darrel
Apr 13 '06 #1
6 1181
>*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
Apr 13 '06 #2
<configuration>
<appSettings>
<add key="XXX" value="YYY" />
</appSettings>
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=MyData.mdf;In tegrated
Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
......

"Darrel" <no*****@nospam.com> wrote in message
news:eQ**************@TK2MSFTNGP04.phx.gbl...
*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").C onnectionString()

as well as this:

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

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

--------------
Object reference not set to an instance of an object.
App_Web_0-ola1a7
--------------

What am I doing wrong?

-Darrel

Apr 13 '06 #3
Hi Darrel,

For web applications, the preferred way to work with configuration file
is to use the new .NET 2.0 WebConfigurationManager class, rather than
ConfigurationManager. For example:

Dim strConnect As String =
WebConfigurationManager.ConnectionStrings("Connect ionStringName").ConnectionString

More info on MSDN:
http://msdn2.microsoft.com/en-us/lib...er(VS.80).aspx

HTH,

Chris

Apr 13 '06 #4
<configuration>
<appSettings>
<add key="XXX" value="YYY" />
</appSettings>
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=MyData.mdf;In tegrated
Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>


THanks, william...that clarified things!

-Darrel
Apr 13 '06 #5
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
Apr 13 '06 #6
Dim strConnect As String =
WebConfigurationManager.ConnectionStrings("Connect ionStringName").ConnectionString

More info on MSDN:
http://msdn2.microsoft.com/en-us/lib...er(VS.80).aspx


Thanks, Chris!

-Darrel
Apr 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ryan N. | last post by:
Hello, I saw a brief blurb on this somewhere and am unable to recall where... In the context of Security, what are some best practices for handling -storing, locating, retrieving- database OLEDB...
4
by: Minh Tran | last post by:
In order to minimize the number of connection strings I have to use to access different databases on the same Sql Server, I was considering storing all stored procedures in just one database. I...
1
by: Taco Bill | last post by:
I am trying to do what I think is a very simple thing but I am getting lost in the documentation. I have a DSN set up on a server .. and I want to place a connection string in my ASPX page so I...
1
by: Gerard Marshall Vignes | last post by:
I was recently cautioned against storing an ADO.NET Connection String in the Windows Registry because access to the Windows Registry would be serialized and therefore impact scalability. I have...
8
by: Natan | last post by:
Hi, I`m creating a asp.net intranet system, and would like to put all the logic of the system in a single dll. That is, when i need to create an user for example, i would use "User.Check()" and...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
2
by: Mike P | last post by:
I've always put my connection strings in the web.config, but I've just recently seen an example of a connection string in a resource file. What are the advantages of doing this, and could you do it...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
6
by: BillE | last post by:
I have defined connection strings in the settings tab of the properties page of a Windows forms project. Users need to be able to modify the connection string through the application - how do I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.