Joe,
string sqlDbConn = ConfigurationManager.AppSettings["SQLDBConn"];
1) need a reference to System.Configuration assembly.
2) you can make this static and put it in Global.asax (at class level) and
refer to it from any page as "Global.sqlDbConn". You can also just store it
in Application State by reading and assigning in the Global Application_Start
handler method.
3) This should really have been in the ASP.NET group, but I guess that's a
lost cause.
Peter
--
Site:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
Short urls & more:
http://ittyurl.net
"Joe" wrote:
I'd like to specify the connection string to the SQL Server so that I can just
refer to it instead of the full connection string.
Here's what I have:
<app.config>
<appSettings>
<add key="SQLDBConn",value="Server=SqlSrvr;Database=DBN ame;User
ID=uid;Password=pwd;Trusted_Connection=False" />
</appSettings>
Then in my code I replace the connection string with the key "SQLDBConn":
SqlConnection conn = new SqlConnection(SQLDBConn);
But I get an error when I compile that it does not exist in the namespace.
What have I done wrong?
Thanks.