include DB connection string?

R

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=password;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
 
S

Shiva

How about storing the connection string in the web.config file? And access
it when required?

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=password;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
 
D

David Wier

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("MyDBConnection"))


David Wier
MCP, MVP ASP.NET, ASPInsider
http://aspnet101.com
http://aspexpress.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top