Connecting Tech Pros Worldwide Forums | Help | Site Map

Weird problem with connection strings

Harry Strybos
Guest
 
Posts: n/a
#1: Jun 14 '07
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.Connecti onStrings

'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|aspn etdb.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.



Andrew Morton
Guest
 
Posts: n/a
#2: Jun 15 '07

re: Weird problem with connection strings


Harry Strybos wrote:
Quote:
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 -
>
<snip code>
Quote:
'the above returns 3 (THREE) instances (all the same) of the
following:
'name = "LocalSqlServer"
'connection string = "data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspn etdb.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


Patrice
Guest
 
Posts: n/a
#3: Jun 15 '07

re: Weird problem with connection strings


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).

---
Patrice


"Harry Strybos" <harry_NOSPAM@ffapaysmart.com.aua écrit dans le message de
news: %23OL7NBtrHHA.4768@TK2MSFTNGP02.phx.gbl...
Quote:
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.Connecti onStrings
>
'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|aspn etdb.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.
>
>

Harry Strybos
Guest
 
Posts: n/a
#4: Jun 17 '07

re: Weird problem with connection strings



"Patrice" <http://www.chez.com/scribe/wrote in message
news:uuY$vD0rHHA.3896@TK2MSFTNGP04.phx.gbl...
Quote:
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).
>
---
Patrice
>
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.v b:line 62"

even though _colConnectStrings has a count of 3 and has Databasename as one
of its items. Still a strange problem
Quote:
>
"Harry Strybos" <harry_NOSPAM@ffapaysmart.com.aua écrit dans le message
de news: %23OL7NBtrHHA.4768@TK2MSFTNGP02.phx.gbl...
Quote:
>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.Connect ionStrings
>>
>'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|asp netdb.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.
>>
>>
>
>

Closed Thread