Connection string in web.config

aliweb

Active member
Joined
Sep 14, 2005
Messages
40
Programming Experience
3-5
Hello,

By default this is written in web.config

Code:
[SIZE=2][COLOR=#0000ff]<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]sessionState[/COLOR][/SIZE][SIZE=2][COLOR=#ff00ff] 
[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]mode[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="InProc"
[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]stateConnectionString[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="tcpip=127.0.0.1:42424"
[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]sqlConnectionString[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="data source=127.0.0.1;Trusted_Connection=yes"
[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]cookieless[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="false"[/COLOR][/SIZE][SIZE=2][COLOR=#ff00ff] 
[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]timeout[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="20"[/COLOR][/SIZE][SIZE=2][COLOR=#ff00ff] 
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]/>
[/COLOR][/SIZE]
My question is how can I use this sqlConnectionString defined here in my web page? I mean when I tried to print it using

Response.Write (session("sqlConnectionString"))
and
Response.Write (sqlConnectionString)

but it didn't work. So what is the purpose of it and how can I use it in y web page.
 

Craig

Well-known member
Joined
Oct 15, 2005
Messages
110
Location
United Kingdom
Programming Experience
Beginner
When I generate a connection string it comes up with this:


Code:
	<connectionStrings>
		<add name="DatabaseConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
	</connectionStrings>
and to get the connectionstring i do

Code:
Response.Write(ConfigurationManager.ConnectionStrings("DatabaseConnectionString1"))
 

giadich

Well-known member
Joined
May 20, 2007
Messages
260
Location
Houston, TX
Programming Experience
5-10
The connection string you mentioned is created by default and is only used when session state is set to use SQL Server.

You should add your own connection string to <appSettings> node of the web.config file.
 
Top Bottom