Solved

ASP.NET question

Posted on 2004-05-01
2
175 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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now