473,396 Members | 1,940 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,396 software developers and data experts.

Connection String Problem

Hello,

I am need to get a connection string details. I am doing as follows:

01: Dim connectionStrings As New ConnectionStringSettingsCollection
02: Dim connectionString As New ConnectionStringSettings
03: connectionString = connectionStrings.Item("MyConn")
04: Console.WriteLine(" Connection String: ",
connectionString.ConnectionString) *** ERROR ***
05: Console.WriteLine(" Name: ", connectionString.Name)
06: Console.WriteLine(" Provider Name: ",
connectionString.ProviderName)

I get my first error on line 04
System.NullReferenceException: Object reference not set to an
instance of an object.

To check my connection string I did the following:
Dim otherConnectionString As String =
ConfigurationManager.ConnectionStrings("MyConn").C onnectionString
Response.Write(otherConnectionString)

And I get:
Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and
Settings\User\My Documents\Visual Studio
2005\WebSites\MySite\App_Data\MySite.mdb; User Id=; Password=;

Which proves I have the connection string with name MyConn in my
web.config.

Could someone tell me what am I doing wrong?

I tried everything I could think off.

Thanks,
Miguel

Nov 6 '06 #1
2 2853
Is there a reason you can't juse use
ConfigurationManager.ConnectionStrings("MyConn").C onnectionString ?

You're code doesn't make too much sense to me.
connectionStrings.Item("MyConn") will return null/nothing. All you do is
create a new collection and try to retrieve a value. It's like doing:

dim arr as new ArrayList()
dim o as object = arr(0);

you never put anything into arr.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"shapper" <md*****@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
Hello,

I am need to get a connection string details. I am doing as follows:

01: Dim connectionStrings As New ConnectionStringSettingsCollection
02: Dim connectionString As New ConnectionStringSettings
03: connectionString = connectionStrings.Item("MyConn")
04: Console.WriteLine(" Connection String: ",
connectionString.ConnectionString) *** ERROR ***
05: Console.WriteLine(" Name: ", connectionString.Name)
06: Console.WriteLine(" Provider Name: ",
connectionString.ProviderName)

I get my first error on line 04
System.NullReferenceException: Object reference not set to an
instance of an object.

To check my connection string I did the following:
Dim otherConnectionString As String =
ConfigurationManager.ConnectionStrings("MyConn").C onnectionString
Response.Write(otherConnectionString)

And I get:
Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and
Settings\User\My Documents\Visual Studio
2005\WebSites\MySite\App_Data\MySite.mdb; User Id=; Password=;

Which proves I have the connection string with name MyConn in my
web.config.

Could someone tell me what am I doing wrong?

I tried everything I could think off.

Thanks,
Miguel

Nov 7 '06 #2
Hi,

The point in this was to be able to connect to a database, an Access or
SQL.
So I was trying to check the provider of the connection string and have
two different codes.

Anyway, I found out that there is a Data.Common class with the factory
provider which can access any database.

I am using it now. I think this is the way to go and it solves my
problem. I don't need to find the provider name anymore.

Thanks,
Miguel

Karl Seguin [MVP] wrote:
Is there a reason you can't juse use
ConfigurationManager.ConnectionStrings("MyConn").C onnectionString ?

You're code doesn't make too much sense to me.
connectionStrings.Item("MyConn") will return null/nothing. All you do is
create a new collection and try to retrieve a value. It's like doing:

dim arr as new ArrayList()
dim o as object = arr(0);

you never put anything into arr.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"shapper" <md*****@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
Hello,

I am need to get a connection string details. I am doing as follows:

01: Dim connectionStrings As New ConnectionStringSettingsCollection
02: Dim connectionString As New ConnectionStringSettings
03: connectionString = connectionStrings.Item("MyConn")
04: Console.WriteLine(" Connection String: ",
connectionString.ConnectionString) *** ERROR ***
05: Console.WriteLine(" Name: ", connectionString.Name)
06: Console.WriteLine(" Provider Name: ",
connectionString.ProviderName)

I get my first error on line 04
System.NullReferenceException: Object reference not set to an
instance of an object.

To check my connection string I did the following:
Dim otherConnectionString As String =
ConfigurationManager.ConnectionStrings("MyConn").C onnectionString
Response.Write(otherConnectionString)

And I get:
Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and
Settings\User\My Documents\Visual Studio
2005\WebSites\MySite\App_Data\MySite.mdb; User Id=; Password=;

Which proves I have the connection string with name MyConn in my
web.config.

Could someone tell me what am I doing wrong?

I tried everything I could think off.

Thanks,
Miguel
Nov 7 '06 #3

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

Similar topics

6
by: Paul Robinson | last post by:
I am developing a website in ASP that connects to a Sybase database. However, when I try to open a connection to the database the page will not load. The script does not timeout, nor the...
17
by: AMC | last post by:
Hi, I'm using an include file to store the connection string to a database. Whenever I try to reference that string to open a connection in the page that includes the file I get the error 'empy...
0
by: Bob | last post by:
I have an ASP.NET web application that has been running without any problems for a while. I recently transferred the site to shared hosting and had multiple users start to use the site. The problem...
4
by: Rahul Anand | last post by:
Getting SQL Exception when trying to implement Connection based Trasaction using SQL Helper class. I am using the follwing function to execute my stored procs: -=-=-=- ExecuteScalar(ByVal...
6
by: Bala Nagarajan | last post by:
Hello, I am using Oracle 9i in my application and facing a problem with the connection string. In the datasource attribute of the connection string i had to specify an entry in "tnsnames.ora"...
14
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review,...
2
by: RyoSaeba | last post by:
Hello, I have a problem with the session state set to Sql Server (AspNet 1.1, Windows Server 2003 on an Application Center cluster, Sql Server 2000 on another server). Sometimes, when many user...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
3
by: Harry Strybos | last post by:
Hi All I have a really strange problem occurring in my application. When I read in the application settings for connection strings the following happens: Here are my connection string settings...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.