MS SQL Server
  Home arrow MS SQL Server arrow SQL Connection: Connecting to Multiple Dat...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

SQL Connection: Connecting to Multiple Databases
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 21
    2005-08-22

    Table of Contents:
  • SQL Connection: Connecting to Multiple Databases
  • Saving multiple connections in Web.config
  • Code
  • Connection Using Dynamic Properties of the SQLConnection Control

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    SQL Connection: Connecting to Multiple Databases


    (Page 1 of 4 )

    As businesses may have more than one SQL Server holding their data, it is of interest to know the technique of connecting to mulitple servers through saving connection information in the configuration of the application. In fact, it is a recurring question in several forums. This tutorial addresses this question in detail.

    Using application settings in Web.Config

    In this tutorial, the storing of a connection string in a web.config file and its usage for connecting to multiple databases will be considered. One advantage of storing information in a web.config file is that all testing can be done with a development database, and when going into production all that needs to be changed is the web.config file information. The web.config file is secure because its accessibility is limited. The manner in which the web.config file is set up to store database information, assuming a connection to the pubs database on the local server accessed with SQL authentication, is as follows:

    <Configuration>
    <appSettings>
    <add key="ConnectionString"
    value="DATABASE=pubs;Server=localhost;UID=sa:"/>
    </appSettings>
    </Configuration>
    

    It is also possible to store the same database information in an external file data.config and link to it. In this case the key/value pair information is carried in the external file. Once the web.config carries this information it can be retrieved by using code as follows:

     

    Code in C#:
    string strConn=ConfigurationSettings.AppSettings["ConnectionString"];


    Code in VB.NET
    DIM conn as String conn=ConfigurationSettings.AppSettings("ConnectionString")

    More MS SQL Server Articles
    More By Jayaram Krishnaswamy


       · This tutorial is a continuation of an article you may find at the following...
       · Once you have your user-chosen connection string, how can you keep it for further...
       · This article is just about keeping multiple connections strings in one place, namely...
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway