Usage of database connection word in Web.config

Source: Internet
Author: User
Tags config ole sybase
web| Data | database | database connection


In the settings of the Web program in asp.net we must use the Web.config to store the database connection Word. Actually, it's a

Good practice, because it can save us a lot of trouble can also help us avoid unnecessary dislocation, yes, in many cases

That's what I do. It records this information through XML. Specifically in <appSettings>....</appSettings> this

Tag. Here is an example of an Oracle, as follows:

<appSettings>
<add key= "oracleconnectionstring" value= "PROVIDER=ORAOLEDB.ORACLE.1;
Persist Security Info=false; Password=blah; User id=greg;data source=sph; "/>
<add key= "sqlConnectionString" value= "Data source=sql1;initial catalog=id_v;
Integrated security=sspi;persist security Info=false;workstation id=th03d374;
Packet size=4096 "/>
<appSettings>

And in your application you just have to write it, as follows:

String conn = configurationsettings.appsettings["Oracleconnectionstring"];
OleDbConnection myconnection = new OleDbConnection (conn);

It's easy, isn't it? Do not have to enter the same connection word every time, do not remember the annoying information, only need a good memory

Name is OK.

Okay, I'm here to give you some other connection words.

MySQL's connection word:
ConnectionString = "Data source=localhost;" +
                                "Database=mysqldatabase" +
                                "User id=myusername;" +
                               "password= mypassword; "+
                               "Command Logging=false";
OLE DB:
IBM as/400 OLE DB

' vb.net
Dim ooledbconnection as Oledb.oledbconnection
Dim sconnstring as String = _
            "provider=ibmda400. Datasource.1; "& _
          " Data source=myas400dbname; " & _
           User Id=myusername & _
            "Password=mypassword"
Ooledbconnection = New Oledb.oledbconnection (sconnstring)
Ooledbconnection.open ()
 
JET OLE DB

' vb.net
Dim ooledbconnection as Oledb.oledbconnection
Dim sconnstring as String = _
          "Provider=Microsoft.Jet.OLEDB.4.0" & _
          "Data Source=c:\mypath\myjet.mdb & _
        " User Id=admin "& _
        " password= "
Ooledbconnection = New Oledb.oledbconnection (sconnstring)
Ooledbconnection.open ()
 
Oracle OLE DB

' vb.net
Dim ooledbconnection as Oledb.oledbconnection
Dim sconnstring as String = _
          "Provider=oraoledb.oracle" & _
          "Data Source=myoracledb & _
        " User id=myusername; " & _
         "Password=mypassword"
Ooledbconnection = New Oledb.oledbconnection (sconnstring)
Ooledbconnection.open ()
 
SQL Server OLE DB

' vb.net
Dim ooledbconnection as Oledb.oledbconnection
Dim sconnstring as String = _
          "Provider=sqloledb" & _
         " Data Source=myservername "& _
        " Initial catalog= MyDatabaseName "& _
        " User id=myusername; "& _
          "Password=mypassword"
Ooledbconnection = New oledb.oledbconnection ( sconnstring)
Ooledbconnection.open ()
 
Sybase ASE OLE DB

' VB.net
Dim Ooledbconnection as Oledb.oledbconnection
Dim sConnString as String = _
"Provider=sybase ASE OLE DB Provider;" & _
"Data source=mydatasourcename;" & _
"Server name=myservername;" & _
"Database=mydatabasename;" & _
"User id=myusername;" & _
"Password=mypassword"
Ooledbconnection = New oledb.oledbconnection (sconnstring)
Ooledbconnection.open ()

SQL Server in System.Data.SqlClient

SqlConnection osqlconn = new SqlConnection ();
osqlconn.connectionstring = "Data source= (local);"
"Initial catalog=mysqlserverdbname;" +
"Integrated SECURITY=SSPI";
Osqlconn.open ();




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.