You can also define your database connection setting in web.config
file like given below.
And it will not be required to compile application when changes are
need to be done in
Database connection string just change in web.config
<!-- Start-- Write in web.config -->
<appSettings>
<add key="DBString1" value="Data Source=machineName
\SQLEXPRESS;Initial Catalog=DBName; User ID=sa;password=xyz;" />
<add key="DBString2" value="Data Source=machineName
\SQLEXPRESS;Initial Catalog=DBName; Integrated Security=True" />
</appSettings>
<!-- End-- Write in web.config -->
<!-- Start-- read in code file -->
Dim DBString1 As String =
System.Configuration.ConfigurationManager.AppSettings("DBString1").ToString()
Dim DBString2 As String =
System.Configuration.ConfigurationManager.AppSettings("DBString2").ToString()
<!-- End-- read in code file -->
On Oct 27, 8:09 pm, Davej <[email protected]> wrote:
> I'm a beginner and have been playing around with VB 2008 and SQL
> Server 2008 and am confused about the (Connection string) that must be
> defined in the project settings. Surely you don't want a recompile if
> the location of the database server changes -- do you?
>
> I found this article...
>
> http://www.codeproject.com/KB/vb/PersistConnectionStrings.aspx?displa...
>
> ...but I haven't been able to get it to work.
>
> Thanks for any help