473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

include DB connection string?

rc
Hello,

We have several asp.net pages (.aspx) that access SQL server. Currently, we
use a connection string like this:

Conn=New SqlConnection("Server=servername;uid=id;pwd=passwo rd;database=db")

Is there a way to have the connection string (the part in quotes) included
from another file?

The reason I ask is, in the future, we will move the SQL data to another
machine and thus, a different connect string will be needed. It would be
nice to only change one file instead of every page that needs the
connection.

I know include files are commonly used all the time, but I'm not familiar
with how to only include one line at this location.

Any insight would be helpful.

Thank you
Nov 18 '05 #1
3 1604
How about storing the connection string in the web.config file? And access
it when required?

"rc" <no@email.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
Hello,

We have several asp.net pages (.aspx) that access SQL server. Currently, we
use a connection string like this:

Conn=New SqlConnection("Server=servername;uid=id;pwd=passwo rd;database=db")

Is there a way to have the connection string (the part in quotes) included
from another file?

The reason I ask is, in the future, we will move the SQL data to another
machine and thus, a different connect string will be needed. It would be
nice to only change one file instead of every page that needs the
connection.

I know include files are commonly used all the time, but I'm not familiar
with how to only include one line at this location.

Any insight would be helpful.

Thank you

Nov 18 '05 #2
rc
Ahh,

I hadn't thought of that, I'll give it a try.

Thank you
"Shiva" <sh******@online.excite.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
How about storing the connection string in the web.config file? And access
it when required?

"rc" <no@email.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
Hello,

We have several asp.net pages (.aspx) that access SQL server. Currently, we use a connection string like this:

Conn=New SqlConnection("Server=servername;uid=id;pwd=passwo rd;database=db")


Is there a way to have the connection string (the part in quotes) included
from another file?

The reason I ask is, in the future, we will move the SQL data to another
machine and thus, a different connect string will be needed. It would be
nice to only change one file instead of every page that needs the
connection.

I know include files are commonly used all the time, but I'm not familiar
with how to only include one line at this location.

Any insight would be helpful.

Thank you

Nov 18 '05 #3
Exactly - - like this:
<appSettings>
<add key="MyDBConnection"
value="server=YourServer;uid=Username;pwd=Password ;database=DBName" />
</appSettings>
Then:
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("M yDBConnection"))
David Wier
MCP, MVP ASP.NET, ASPInsider
http://aspnet101.com
http://aspexpress.com
"Shiva" <sh******@online.excite.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
How about storing the connection string in the web.config file? And access
it when required?

"rc" <no@email.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
Hello,

We have several asp.net pages (.aspx) that access SQL server. Currently, we use a connection string like this:

Conn=New SqlConnection("Server=servername;uid=id;pwd=passwo rd;database=db")


Is there a way to have the connection string (the part in quotes) included
from another file?

The reason I ask is, in the future, we will move the SQL data to another
machine and thus, a different connect string will be needed. It would be
nice to only change one file instead of every page that needs the
connection.

I know include files are commonly used all the time, but I'm not familiar
with how to only include one line at this location.

Any insight would be helpful.

Thank you

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brad | last post by:
Dear friends, I am working on a App. at my work place, now wanting to set it up at home but for some reason I keep getting this error : ADODB.Command (0x800A0BB9) Arguments are of the...
3
by: mannik | last post by:
Hi I've made a simple winform with access to an Access database. I work on my machine but when I install the MSI on another machine it looks for the database the wrong place, what would be the...
8
by: Dave | last post by:
Everyone keeps telling me that I should protect my database connection information by defining the connection string in a separate file (presumably one that is not in the application directory)....
5
by: Neil Steventon | last post by:
Hi all, I used to use the include statement in classic asp to centralise my database connection, is there a better way in asp.net, whats the norm?. Thanks alot Neil
2
by: Steven K | last post by:
Hello, I have an include file (../../Connections/pricex.inc). That I use to declare my variables and build my connection string. I tried using the following, but got the error: Compiler Error...
3
by: Dave | last post by:
I have different database connections that I use for DEV and PROD versions of our web app. I want to put the database connection string in one location so I only have to change it once when we...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.