Solved

ASP.NET question

Posted on 2004-05-01
2
218 Views
Last Modified: 2010-04-06
I have a current CMS project which updates data into the database. I have to change this CMS so that it could insert the data into other database also if user wants by providing a check box. I do not want to change much of the code. It takes connection string from an xml file. Is there a easy where much of coding is not necessary.


Thanks,

Tech.
0
Comment
Question by:tech_question
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 500 total points
ID: 10973735
When they submit the data, instantiate the connection object based on whether the checkbox is checked. Here is some psuedo-code.

Dim myConnection As SqlConnection

If (checkbox is checked) Then
     myConnection = New SqlConnection(other connection string)
Else ' checkbox is not checked
     myConnection = New SqlConnection(first connection string)

' database access code
0
 
LVL 1

Expert Comment

by:Daniel_Hegener
ID: 10977209
If you want to be completely flexible store your connection string in the registry or some other config file and use an array based method to get the correct connection string.
To do this you have to create a simple method that reads all available connections strings and writes them into an array. Then you could just say in your server side code:

myConnectionStrings = GetConnectionStrings();
myConnection = New SqlConnection( myConnectionStrings[ Request.QueryString.Get( "myConnectionStringId" ) ] )

and in your html code:

<select name="myConnectionStringId">
  <option value="0">production db</option>
  <option value="1">archive db</option>
  <option value="2">test db</option>
  <option value="3">test db2</option>
</select>

This way you would never have to change your code again in case you want to change the db server. You could just change your registry or ini-file or something like that.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question