SQL Connection string in app.config file

ICW

Active member
Joined
Mar 27, 2006
Messages
25
Programming Experience
Beginner
Hi I have added an app.config file and put my connection string into it.
below is the content of the app.config file.
<?xml version="1.0" encoding="utf-8" ?>
<
configuration>
<
connectionStrings>
<add name="DatabaseConnection"
connectionString="Data Source=ICWSQL2K;Initial Catalog= HACardio;user id=username;password=password;"
providerName="System.Data.SqlClient" />
</
connectionStrings>
</
configuration>

I have also added the following to the top of my form;
Imports System.Configuration.ConfigurationSettings

I now need to call my connection string (which is called "DatabaseConnection") in my config file so i can connect to my database. But I am not sure of the syntax. Can anyone please help?
best regards

I am using vs2003 - should I have also used <appsettings> instead of <connectionstrings> in my config file
ICW

 
whats wrong with my SqlConnection code?

I am trying to connect to a database via a config file. I get an error complaining about the line 3 of the app.config
---------------------------------------------------------------

PHP:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Configuration.ConfigurationSettings
Module Module1
 
Public SqlConnection1 As SqlConnection = New SqlConnection(AppSettings("DataBaseConnection"))
 
End Module

Here is the stuff from the app.config file

PHP:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appsettings>
<add key="DataBaseConnection" value="ICWSQL2K;database=HACardio;uid=username;pwd=password;" />
</appsettings>
</configuration>
 
Vb.net provides a very useful thing called dynamic properties. It just so happens that a connection string is one of them. It will automatically save your connection string to your app config file and 'get' it at runtime. Check out dynamic properties.
 
DataBaseConnection (in code) is NOT the same as DatabaseConnection (in the xml)....

-tg
 
I have tried various cases. Doesn't seem to make a difference. Where can i access dynamic properties from within the form?

thanks

icw
 
Back
Top