Universal Database Connection Program-2

Source: Internet
Author: User
Tags exit end sql
Program | data | database | database connection '---------------------------------------------------
Function Getexcelrecordset (FileName, SQL)
Set Getexcelrecordset = Getotherrs ("Excel", FileName, SQL, 2)
End Function

'---------------------------------------------------
Function Getexcelstaticrecordset (FileName, SQL)
Set Getexcelstaticrecordset = Getotherrs ("Excel", FileName, SQL, 3)
End Function

'---------------------------------------------------
Function Gettextrecordset (Directory, SQL)
Set Gettextrecordset = Getotherrs ("Text", Directory, SQL, 2)
End Function

'---------------------------------------------------
Function Gettextstaticrecordset (Directory, SQL)
Set Gettextstaticrecordset = Getotherrs ("Text", Directory, SQL, 3)
End Function

'---------------------------------------------------
Function Getsqlserverrecordset (conn, source)
Dim RS

Set rs = Server.CreateObject ("ADODB.") Recordset ")
Rs. Open Source, Conn, 2, 2
Set Getsqlserverrecordset = rs
End Function

'---------------------------------------------------
Function Getsqlserverstaticrecordset (conn, source)
Dim RS

Set rs = Server.CreateObject ("ADODB.") Recordset ")
Rs. Open Source, Conn, 3, 2
Set Getsqlserverstaticrecordset = rs
End Function

'---------------------------------------------------
Function getconnection (Param)
Dim Conn

On Error Resume Next
Set getconnection = Nothing
Set conn = Server.CreateObject ("ADODB. Connection ")
If err.number <> 0 Then Exit Function

Conn. Open Param
If err.number <> 0 Then Exit Function
Set getconnection = conn
End Function

'---------------------------------------------------
Function Getmdbrs (FileName, Source, Cursor, Password)
Dim Conn, RS

On Error Resume Next
Set Getmdbrs = Nothing
If Len (Password) = 0 Then
Set conn = getmdbconnection (FileName)
Else
Set conn = getsecuredmdbconnection (FileName, Password)
End If
If Conn is nothing Then Exit Function

Set rs = Server.CreateObject ("ADODB.") Recordset ")
If err.number <> 0 Then Exit Function

Rs. Open source, Conn, Cursor, 2
If err.number <> 0 Then Exit Function
Set Getmdbrs = rs
End Function

'---------------------------------------------------
Function Getotherrs (DataType, Path, SQL, Cursor)
Dim Conn, RS
On Error Resume Next
Set Getotherrs = Nothing

Select Case DataType
Case "DBF"
Set conn = getdbfconnection (Path)
Case "DBC"
Set conn = getdbcconnection (Path)
Case "Excel"
Set conn = getexcelconnection (Path)
Case "Text"
Set conn = gettextconnection (Path)
End Select
If Conn is nothing Then Exit Function

Set rs = Server.CreateObject ("ADODB.") Recordset ")
If err.number <> 0 Then Exit Function

Rs. Open SQL, Conn, Cursor, 2
If err.number <> 0 Then Exit Function
Set Getotherrs = rs
End Function

'---------------------------------------------------
Function Getsqlserverrs (Computer, UserID, Password, Db, source, Cursor)
Dim Conn, RS

On Error Resume Next
Set Getsqlserverrs = Nothing
Set conn = getsqlserverconnection (Computer, UserID, Password, Db)
If Conn is nothing Then Exit Function

Set rs = Server.CreateObject ("ADODB.") Recordset ")
If err.number <> 0 Then Exit Function

Rs. Open source, Conn, Cursor, 2
If err.number <> 0 Then Exit Function
Set Getsqlserverrs = rs
End Function
%>
Use the method--copy it down to save it as a file, and then use the #include "filename" to call the inside subroutine.

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.