connection string bug? Big Problem.

B

BillE

What the heck is going on?

I have several connection strings in my project.

When I change one of them, they are all changed to the same value!

Sometimes, if I change one connection string in the Settings tab of the
Project Properties page and then close the properties, I get the following
message when I open the properties again:

Value of setting 'connstring' was changed in the app.config file
The current value in the .settings file is ------
The new value in the app.config file is -----
Do you want to update the value in the .settings file?

I get the message for each of the other connection string entries.

This is a big problem.

This is a VS 2008, vb.net windows forms project.
 
J

JimmyKoolPantz

What the heck is going on?

I have several connection strings in my project.

When I change one of them, they are all changed to the same value!

Sometimes, if I change one connection string in the Settings tab of the
Project Properties page and then close the properties, I get the following
message when I open the properties again:

    Value of setting 'connstring' was changed in the app.config file
    The current value in the .settings file is ------
    The new value in the app.config file is -----
    Do you want to update the value in the .settings file?

I get the message for each of the other connection string entries.

This is a big problem.

This is a VS 2008, vb.net windows forms project.

Im not sure where your declaring your connection strings it sounds
like you have it in the app.config file which is a good secure place
for it. I normally use C# ;however, I will demonstrate how we would
do something like this at work

We would problably create a new class in the project (usually for
global functions and variables)

Public Class c
#Region "Connection Strings"
Public Const connectionString1 As String = "ConnectionString1"
Public Const connectionString2 As String = "ConnectionString2"
Public Const connectionString3 As String = "ConnectionString3"
#End Region
End Class


and then somewhere in your applications you can call the connection
strings

Dim cn = New SqlConnection(c.connectionString1)

if you are actually changing the connection strings in the properties
of your application (on the fly) I would do something like
Public Class c
#Region "Connection Strings"
Public connectionString1 As String = "ConnectionString1"
Public connectionString2 As String = "ConnectionString2"
Public connectionString3 As String = "ConnectionString3"
#End Region
End Class

And then declare a new instance somewhere in your application
public MyConnectionStrings as c = new c

Dim cn = New SqlConnection(MyConnectionString.ConnectionString1)

Finally, if all connectionstrings have the same value and u dont want
them to, then I would check your code to see if your updating the
correct connection string in your code.

- Jimmy
 
B

BillE

I manage connection strings in the Project Properties screen, on the
Settings tab.

What the heck is going on?

I have several connection strings in my project.

When I change one of them, they are all changed to the same value!

Sometimes, if I change one connection string in the Settings tab of the
Project Properties page and then close the properties, I get the following
message when I open the properties again:

Value of setting 'connstring' was changed in the app.config file
The current value in the .settings file is ------
The new value in the app.config file is -----
Do you want to update the value in the .settings file?

I get the message for each of the other connection string entries.

This is a big problem.

This is a VS 2008, vb.net windows forms project.

Im not sure where your declaring your connection strings it sounds
like you have it in the app.config file which is a good secure place
for it. I normally use C# ;however, I will demonstrate how we would
do something like this at work

We would problably create a new class in the project (usually for
global functions and variables)

Public Class c
#Region "Connection Strings"
Public Const connectionString1 As String = "ConnectionString1"
Public Const connectionString2 As String = "ConnectionString2"
Public Const connectionString3 As String = "ConnectionString3"
#End Region
End Class


and then somewhere in your applications you can call the connection
strings

Dim cn = New SqlConnection(c.connectionString1)

if you are actually changing the connection strings in the properties
of your application (on the fly) I would do something like
Public Class c
#Region "Connection Strings"
Public connectionString1 As String = "ConnectionString1"
Public connectionString2 As String = "ConnectionString2"
Public connectionString3 As String = "ConnectionString3"
#End Region
End Class

And then declare a new instance somewhere in your application
public MyConnectionStrings as c = new c

Dim cn = New SqlConnection(MyConnectionString.ConnectionString1)

Finally, if all connectionstrings have the same value and u dont want
them to, then I would check your code to see if your updating the
correct connection string in your code.

- Jimmy
 
D

dotNetDave

Bill, you are doing it the correct way. Connection strings should never be
hard coded in the assembly.

It sounds like you have some sort of bug (maybe) with your settings. Just
for a test, have you created a new application and done the same thing? Do
you get the same results?

David

======================================
David McCarter [Microsoft MVP]
www.dotNetTips.com
David McCarter''''s .NET Coding Standards available at:
http://www.cafepress.com/geekmusicart.1654787045
 
B

BillE

Thanks for your response.

Yes, I created a new project and added four connection strings.
I saved everything, and modified one of the connection strings and saved
again.
Two other connection strings were spontaneously changed to the value of the
modified connection string in the app.config file.
I closed the property screen and reopened and I got the error message for
two of the other connection strings. I clicked Yes, and the changes were
saved in the settings file.

This only happens in VS2008 - the problem started when I upgraded from
VS2005.

Bill

dotNetDave said:
Bill, you are doing it the correct way. Connection strings should never be
hard coded in the assembly.

It sounds like you have some sort of bug (maybe) with your settings. Just
for a test, have you created a new application and done the same thing? Do
you get the same results?

David

======================================
David McCarter [Microsoft MVP]
www.dotNetTips.com
David McCarter''''s .NET Coding Standards available at:
http://www.cafepress.com/geekmusicart.1654787045


BillE said:
I manage connection strings in the Project Properties screen, on the
Settings tab.



Im not sure where your declaring your connection strings it sounds
like you have it in the app.config file which is a good secure place
for it. I normally use C# ;however, I will demonstrate how we would
do something like this at work

We would problably create a new class in the project (usually for
global functions and variables)

Public Class c
#Region "Connection Strings"
Public Const connectionString1 As String = "ConnectionString1"
Public Const connectionString2 As String = "ConnectionString2"
Public Const connectionString3 As String = "ConnectionString3"
#End Region
End Class


and then somewhere in your applications you can call the connection
strings

Dim cn = New SqlConnection(c.connectionString1)

if you are actually changing the connection strings in the properties
of your application (on the fly) I would do something like
Public Class c
#Region "Connection Strings"
Public connectionString1 As String = "ConnectionString1"
Public connectionString2 As String = "ConnectionString2"
Public connectionString3 As String = "ConnectionString3"
#End Region
End Class

And then declare a new instance somewhere in your application
public MyConnectionStrings as c = new c

Dim cn = New SqlConnection(MyConnectionString.ConnectionString1)

Finally, if all connectionstrings have the same value and u dont want
them to, then I would check your code to see if your updating the
correct connection string in your code.

- Jimmy
 
R

Ross Culver

Bill,

Did you ever get this issue resolved?

While my connection strings are not synchronizing to the same value, I am
getting this error for every connection string upon clicking the Settings
link in the project manager, and these strings have not been modified in
months.


BillE said:
Thanks for your response.

Yes, I created a new project and added four connection strings.
I saved everything, and modified one of the connection strings and saved
again.
Two other connection strings were spontaneously changed to the value of the
modified connection string in the app.config file.
I closed the property screen and reopened and I got the error message for
two of the other connection strings. I clicked Yes, and the changes were
saved in the settings file.

This only happens in VS2008 - the problem started when I upgraded from
VS2005.

Bill

dotNetDave said:
Bill, you are doing it the correct way. Connection strings should never be
hard coded in the assembly.

It sounds like you have some sort of bug (maybe) with your settings. Just
for a test, have you created a new application and done the same thing? Do
you get the same results?

David

======================================
David McCarter [Microsoft MVP]
www.dotNetTips.com
David McCarter''''s .NET Coding Standards available at:
http://www.cafepress.com/geekmusicart.1654787045


BillE said:
I manage connection strings in the Project Properties screen, on the
Settings tab.

What the heck is going on?

I have several connection strings in my project.

When I change one of them, they are all changed to the same value!

Sometimes, if I change one connection string in the Settings tab of the
Project Properties page and then close the properties, I get the
following
message when I open the properties again:

Value of setting 'connstring' was changed in the app.config file
The current value in the .settings file is ------
The new value in the app.config file is -----
Do you want to update the value in the .settings file?

I get the message for each of the other connection string entries.

This is a big problem.

This is a VS 2008, vb.net windows forms project.

Im not sure where your declaring your connection strings it sounds
like you have it in the app.config file which is a good secure place
for it. I normally use C# ;however, I will demonstrate how we would
do something like this at work

We would problably create a new class in the project (usually for
global functions and variables)

Public Class c
#Region "Connection Strings"
Public Const connectionString1 As String = "ConnectionString1"
Public Const connectionString2 As String = "ConnectionString2"
Public Const connectionString3 As String = "ConnectionString3"
#End Region
End Class


and then somewhere in your applications you can call the connection
strings

Dim cn = New SqlConnection(c.connectionString1)

if you are actually changing the connection strings in the properties
of your application (on the fly) I would do something like
Public Class c
#Region "Connection Strings"
Public connectionString1 As String = "ConnectionString1"
Public connectionString2 As String = "ConnectionString2"
Public connectionString3 As String = "ConnectionString3"
#End Region
End Class

And then declare a new instance somewhere in your application
public MyConnectionStrings as c = new c

Dim cn = New SqlConnection(MyConnectionString.ConnectionString1)

Finally, if all connectionstrings have the same value and u dont want
them to, then I would check your code to see if your updating the
correct connection string in your code.

- Jimmy
 

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