Solved

ASP.NET question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

911 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

20 Experts available now in Live!

Get 1:1 Help Now