By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,327 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,327 IT Pros & Developers. It's quick & easy.

SqlConnection1.ConnectionString

P: n/a
I have a project which contain several WinForms. I put a SqlDataAdapter in
Many of the Forms.
I want these SqlConnection1.ConnectionString Point to the same SQL Server.
So I create a Global Const strConnection in a Module
and I change the SqlConnection1.ConnectionString lile and set the
SqlConnection1.ConnectionString = strConnection in the code of each form.
(I find I cannot set the SqlConnection1.ConnectionString to strConnection
the property window)
The problem is the VB often automaticely delete the line and complain
ConnectionString not set.
any idea.

Thanks

'Public Const StrConnection As String = "data source=A;..."

'Public Const StrConnection As String = "data source= B;...."

'Public Const StrConnection As String = "data source=C;..."

Public Const StrConnection As String = "data source=P;..."

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> I want these SqlConnection1.ConnectionString Point to the same SQL Server.

see

http://www.kjmsolutions.com/flexible...tionstring.htm
Nov 20 '05 #2

P: n/a
On Mon, 12 Jan 2004 14:50:27 -0600, James Radke wrote:
Chen,

I put the connection string in the app.exe.config file so I can easily
change it without having to recompile the application. Then I access it
using the system.configuration access methods (I believe they are
app.settings("name of entry") or appsettings("name of entry")..... Not
sure of the exact name of the method call right now....


The correct form is:

System.Configuration.ConfigurationSettings.AppSett ings("ConnectionString")

And in your app.config (or web.config for a web service), add the following
section inside the <configuration></configuration> section:

<appSettings>
<add key="ConnectionString" value="..connection string here.." />
</appSettings>
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.