Solved

ASP.NET question

Posted on 2004-05-01
2
198 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSL Grouping 7 42
PHP parse error 7 60
Format results with PHP 3 77
Select distinct 25 101
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

809 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