Connection String in Global.asax???

Results 1 to 2 of 2

Thread: Connection String in Global.asax???

  1. #1
    Join Date
    Dec 1969

    Default Connection String in Global.asax???

    What is the best way to put the connection string in the Global.asax? Currently I have the following:<BR><BR>Global.asax “Application Start” section:<BR>Dim ConnStr As String<BR>ConnStr = "Data Source=ServerName;database=Database;uid=sa"<BR><BR ><BR>Codebehind page:<BR>Dim objConn As New SqlConnection(ConnStr)<BR>objConn.Open()<BR><BR>Th is works but every time I build/debug the site, it gives an error for each page that the ConnStr is not declared. <BR><BR><BR>Is there a way to have the build process ignore the ConnStr not declared errors?<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Why not use your web.Config file

    Why not use the web.Config file for this matter?<BR>&#060;--Web.Config file--&#062;<BR>&#060;/system.web&#062;<BR> <BR> &#060;appSettings&#062;<BR> &#060;add key="connstring" value="data source=;user id=;password=;database="/&#062;<BR> &#060;/appSettings&#062;<BR><BR>&#060;---Code behind file---&#062; (C#)<BR>using System.Configuration;<BR>SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["connString"]);<BR> <BR><BR>&#060;/configuration&#062;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts