Results 1 to 3 of 3

Thread: Connection String - Oracle & MS SQL

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    150

    Connection String - Oracle & MS SQL

    I'm connecting to Microsoft SQL and Oracle database. To connect to SQL , I have this code in my web.config

    Code:
    <connectionStrings>
    		<add name="BITESampleDBConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    	</connectionStrings>





    Inside my application I'm using this code to connect to oracle :


    Code:
            Try
             
                conn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=XE ;User ID=username;Password=password"
                conn.Open()
    
            Catch
                'DISPLAYING CONNECTION STATUS 
                '----------------------------
    
                Response.Write("Unable to connect to Database ")
                Response.Write("<BR>")
                Response.Write(Err.Description)
                Response.End()
               
            End Try




    now , because I need to connect to oracle alot , can add something to my web.config , instead of using that code to connect to oracle?

    What's your advise

  2. #2
    Addicted Member mday2792's Avatar
    Join Date
    Dec 2006
    Posts
    145

    Re: Connection String - Oracle & MS SQL

    I would suggest pulling the connection string right from the web.config like this:

    Code:
    dim strConn as string = System.Configuation.ConfigurationManager.ConnectionStrings.item("BITESampleDBConnectionString1")
    It's much cleaner and you could even initialize this globally so you don't have to keep doing this.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Connection String - Oracle & MS SQL

    You'll need to change the client namespace you're using for your objects though. For SQL, it was System.Data.SqlClient, but that's only for SQL Server.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width