Page Connections and Web.Config

Results 1 to 2 of 2

Thread: Page Connections and Web.Config

  1. #1
    Join Date
    Dec 1969

    Default Page Connections and Web.Config

    Hi guys, <BR><BR>I&#039;m a newbie to ASP.NET so please bare with me. Now I know in ASP.NET you can define a connection in your web.config file then reference it in your pages. <BR><BR>I&#039;m trying some of the examples in the Web Matrix application and all of them seem to require you to manually restate the connection in every .aspx , for example:<BR><BR>&#060;script runat="server"&#062;<BR><BR>&#039; TODO: update the ConnectionString and Command values for your application<BR><BR>Dim ConnectionString As String = "server=(local);database=pubs;trusted_connection=t rue"<BR><BR>&#060;/script&#062;<BR><BR>I keep typing in my connection manually but is annoying me as I&#039;ve setup the connection in my web.config file, tested it and its worked properly. <BR><BR>Here is the code from my web.config file:<BR><BR>&#060;!-- application specific settings --&#062;<BR>&#060;appSettings&#062;<BR>&#060;add key="MyConnectionString" value="Network Library=DBMSSOCN;Data Source=199.99.999.99,1433;database=test;Initial Catalog=test;User ID=test;Password=test;" /&#062;<BR>&#060;/appSettings&#062;<BR><BR>Now my question is how to I refer to the above connection in the page. Effectively what I want to do is this but i keep getting an error message:<BR><BR>Dim ConnectionString As String = "MyConnectionString"<BR><BR>Any help would be greatly appreciated. <BR><BR>Cheers<BR><BR>James <BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Page Connections and Web.Config

    You would access it like this...<BR><BR>ConnectionString = ConfigurationSettings.AppSetting("MyConnectionStri ng")

Posting Permissions

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