use Application variable, set the value in global.asax's Application_Start event handler <script language="C#" runat="server"> void Application_Start(Object sender, EventArgs E) { Application["ConnectionString"] = "Server=..;Database=..;..."; } </script>then in your code, you can use Application["ConnectionString"] to access the connectionstring: SqlConnection sql = new SqlConnection((String)Application["ConnectionString"]); or you can put the connection string in web.config: ... <appSettings> <add key="ConnectionString" value="(your connection string)" /> </appSettings> ...then in your code,string connstring = ConfigurationSettings.AppSettings["ConnectionString"];
void Application_Start(Object sender, EventArgs E) {
Application["ConnectionString"] = "Server=..;Database=..;...";
}
</script>then in your code, you can use Application["ConnectionString"] to access the connectionstring:
SqlConnection sql = new SqlConnection((String)Application["ConnectionString"]);
or you can put the connection string in web.config:
...
<appSettings>
<add key="ConnectionString" value="(your connection string)" />
</appSettings>
...then in your code,string connstring = ConfigurationSettings.AppSettings["ConnectionString"];