实现ORACLE和SQL Server连接
首先是添加ORACLE和SQL Server的引用(reference),ORACLE用的是它自带的类库
Imports System.Data.SqlClient
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Client
在app.config里面设好connection string,具体如下:
<appSettings >
<add key ="SQLServerConnectionString" value="Data Source=MAPPA03C;Initial Catalog=LVSS;Integrated Security=True"/>
<add key ="OracleConnectionString" value ="DATA SOURCE=lvnet;PASSWORD=lvss;PERSIST SECURITY INFO=False;USER ID=LVSS" />
</appSettings>
<add key ="SQLServerConnectionString" value="Data Source=MAPPA03C;Initial Catalog=LVSS;Integrated Security=True"/>
<add key ="OracleConnectionString" value ="DATA SOURCE=lvnet;PASSWORD=lvss;PERSIST SECURITY INFO=False;USER ID=LVSS" />
</appSettings>
然后便是在获得SQL Server和Oracle连接.
'--------------------------------------------------------------------
'Function: GetSQLServerConn()
'Description: Implement the connection to SQL server database with the connection string in app.config
'Input:
'Remark:
'--------------------------------------------------------------------
Public Shared Function GetSQLServerConn() As SqlConnection
Dim conn As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("SQLServerConnectionString"))
conn.Open()
Return conn
End Function
'--------------------------------------------------------------------
'Function: GetOracleConn()
'Description: Implement the connection to oracle database with the connection string in app.config
'Input:
'Remark:
'--------------------------------------------------------------------
Public Shared Function GetOracleConn() As OracleConnection
Dim conn As New OracleConnection(System.Configuration.ConfigurationManager.AppSettings("OracleConnectionString"))
conn.Open()
Return conn
End Function
'Function: GetSQLServerConn()
'Description: Implement the connection to SQL server database with the connection string in app.config
'Input:
'Remark:
'--------------------------------------------------------------------
Public Shared Function GetSQLServerConn() As SqlConnection
Dim conn As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("SQLServerConnectionString"))
conn.Open()
Return conn
End Function
'--------------------------------------------------------------------
'Function: GetOracleConn()
'Description: Implement the connection to oracle database with the connection string in app.config
'Input:
'Remark:
'--------------------------------------------------------------------
Public Shared Function GetOracleConn() As OracleConnection
Dim conn As New OracleConnection(System.Configuration.ConfigurationManager.AppSettings("OracleConnectionString"))
conn.Open()
Return conn
End Function
-----------------------------------------------------------
佛对我说:你心里有尘。我用力的拭擦。