Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

If I use Server Explorer to create a connection to a SQL 2000 DB, how do I dynamically change the conectionstring property at run time based on my config file.

 

It appears that the code to build teh connection is in the "hidden" or "Do not touch" section of code generated by the designer. So, I can't tell it to look in my config file.

 

If I want the connectionstring to be dynamic, do I have to programatically create it, and not use Server Explorer. If I do that, then I have to programatically create the 38 Datasets I need for all my Drop Down List boxes, also. I'd prefer to use clidk and drag.

 

Please share your wisdon with me.

 

Thanks

Jon

Posted

Robby,

 

You are correct, I am not using 38 connections. I have one for each ASP page.

 

I have a dataadapter for each drop down list.

 

I am not certain what you mean by a creating a public property. I used the Server Explorer wizard to create the connection. Is it possible for me to chagne that between my local SQL db (for dev) and the production SQL server? Will the public property do this?

 

Can I have a single connection that is used by all ASP .net pages?

 

Thanks for your help.

 

Jon

  • Moderators
Posted

Here a simplified solution...

 

Create a Class with a Property in it. This property should return your connection string. Then each page needs to create an instance of this class in order to use/get the connection string.

 

Public Class DataConnectionString
   
      private connString as string = "place your conn string here"

       Public ReadOnly Property getConnectionString() As String
           Get
               Return connString
           End Get
       End Property

End class

 

Then near the top of your aspx pages' Code-Behind...

 

Private CN as new DataConnectionString()

'then one of your routines can consume it as such...

myString = CN.getConnectionString

Visit...Bassic Software
Posted

Another way to do this would be to use the web.config file.

 

 

To do this, in your web.config file you can add this entry at the top(you need to add the appSettings section - case sensitive):

<configuration>

<appSettings>

<add key="DataSource" value="server=localhost;database=something"/>

</appSettings>

 

 

Somewhere in your ASP code, add the following (VB Style):

Imports System.Configuration

 

Dim strconn As String

strconn = ConfigurationSettings.AppSettings.Get("DataSource")

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...