Solved

ASP.NET question

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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

621 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