Weird problem with connection strings

H

Harry Strybos

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 -
<connectionStrings>

<add name="TRM8.UI.My.MySettings.TRM8" connectionString="Data
Source=SQLDATA;Initial Catalog=TRM8_PROD;Integrated Security=True"

providerName="System.Data.SqlClient" />

<add name="TRM8.UI.My.MySettings.TRM8_Test" connectionString="Data
Source=SQLDATA;Initial Catalog=TRM8_UAT;Integrated Security=True"

providerName="System.Data.SqlClient" />

</connectionStrings>

Now when i read in these settings -

Private Sub New()
_colConnectStrings =
System.Configuration.ConfigurationManager.ConnectionStrings

'this is for test purposes

Dim conEnum As IEnumerator = _colConnectStrings.GetEnumerator()

Dim i As Integer = 0

While conEnum.MoveNext()

Dim name As String = _colConnectStrings(i).Name

Dim connectionString As String = _

_colConnectStrings(name).ConnectionString

Dim provider As String = _

_colConnectStrings(name).ProviderName

End While

'the above returns 3 (THREE) instances (all the same) of the following:

'name = "LocalSqlServer"

'connection string = "data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true"

'provider = "System.Data.SqlClient"

End Sub

The consequence of the above is that I cannot get a connection to my
database (Sql Server 2005) as the _colConnectStrings collection does not
contain my real connection strings.

I do NOT have any setting like it in the app config file, neither do I have
SQLExpress installed on my development machine. I have tried removing my
connection strings from application settings, closing VS and resetting the
connection strings. The project is quite large with some 90k lines of code.
VB.Net 2005 running on WinXP SP2.

This one has me beat. I am unable to find any help on this anywhere.

Thank you in advance for any help you can provide.
 
A

Andrew Morton

Harry said:
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 -
<connectionStrings>

<add name="TRM8.UI.My.MySettings.TRM8" connectionString="Data
Source=SQLDATA;Initial Catalog=TRM8_PROD;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="TRM8.UI.My.MySettings.TRM8_Test" connectionString="Data
Source=SQLDATA;Initial Catalog=TRM8_UAT;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

Now when i read in these settings -
'the above returns 3 (THREE) instances (all the same) of the
following:
'name = "LocalSqlServer"
'connection string = "data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true"
'provider = "System.Data.SqlClient"

The consequence of the above is that I cannot get a connection to my
database (Sql Server 2005) as the _colConnectStrings collection does
not contain my real connection strings.

It *really* looks like it's reading from a different file than the one you
intend. Can you get your computer to search in all files for the data that's
being retrieved? (I'd trust something like Agent Ransack more than Windows'
search for doing that.)

Andrew
 
P

Patrice

You don't update the "i" variable so it returns always the same connection
string (the first one that is AFAIK defined in machine.config).
 
H

Harry Strybos

Patrice said:
You don't update the "i" variable so it returns always the same connection
string (the first one that is AFAIK defined in machine.config).

Thank you for your help. How stupid of me....I did not see the problem with
the i variable.

This whole thing came about because I was getting an null error from the
following:
Return _colConnectStrings.Item(DatabaseName).ToString

gives me this error

"System.NullReferenceException occurred
Message="Object reference not set to an instance of an object."
Source="DAL"
StackTrace:
at DAL.FFAConnStrings.GetConnectStringByRole(String DatabaseName) in
C:\AAProjects.Net\FFAPaySmart.DAL\FFAConnStrings.vb:line 62"

even though _colConnectStrings has a count of 3 and has Databasename as one
of its items. Still a strange problem
 

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