How to use remote access to remote databases using VB and ASP

Source: Internet
Author: User
Tags dsn ole

You can access a remote database in the following ways:
1) access the remote database
2) access to the remote MSSQL database or other relational databases such as Oracle, but the database communication port is blocked by the firewall or cannot be used due to other network reasons

This article only passes the test in Windows advance server and mdac2.8. The other conditions are not guaranteed to run normally.

The MDAC service providers include Microsoft ole db persistence provider and Microsoft ole db remoting provider.

Microsoft ole db remoting provider is used today.

let's take a look at the example of MS Remote:
MS remote-access (JET)
I) ODBC DSN:
oconn. open "Remote Server = http: // ;" & _ // server domain name or IP address. If the server name is displayed on the LAN,
"remote provider = msdasql; "& _
" DSN = advworks; "& _ // note, ODBC here refers to the user name on the server
"uid = admin" & _ // accessing the ODBC to point to the database
"Pwd =;" // see, password

Ii) ole db Provider:
Oconn. Open "provider = MS remote ;"&_
"Remote Server = http: // carl2 ;"&_
"Remote provider = Microsoft. Jet. oledb.4.0 ;"&_
"Data Source =/somepath/mydb. mdb ;",_
"Admin ",""

Iii) ole db Provider custom transaction object
Oconn. Open "provider = MS remote ;"&_
"Remote Server = http: // carl2 ;"&_
"Handler = msdfmap. Handler ;"&_
"Data Source = myadvworksoledbconnecttag ;"

Below is the VBCodeExample, run in VB6 through.
Create an EXE project and add the Microsoft ActiveX Data Objects 2.8 Library to the reference. If 2.8 is not installed, use other versions such as 2.7.
Add two Commands
Add the following code in private sub commandementclick:

Dim cn as new ADODB. Connection
Dim RS as new ADODB. recordset

Set Cn = new ADODB. Connection
Set rs = new ADODB. recordset
CN. Open "provider = MS remote ;"&_
"Remote Server = http: // 192.168.0.160 ;"&_
"Remote provider = msdasql ;"&_
"DSN = pubs ;"&_
"Uid = sa ;"&_
"Pwd = aaa"
Rs. Open "select * from authors", CN
Msgbox Rs. EOF

Add the following code in private sub command2_click:

Dim cn as new ADODB. Connection
Dim RS as new ADODB. recordset

Set Cn = new ADODB. Connection
Set rs = new ADODB. recordset
CN. Open "provider = MS remote ;"&_
"Remote Server = http: // 192.168.0.160 ;"&_
"Remote provider = Microsoft. Jet. oledb.4.0 ;"&_
"Data Source = C:/AAA/pubs. mdb ;"
Rs. Open "select * from authors", CN
Msgbox Rs. EOF

Now let's set it on the server.

First, configure an ODBC named pubs. The database server can be accessed at any time.
Next, go to the IIS manager and find the msadc virtual directory in the default site. By default, this directory is installed to prohibit access from any IP addresses. Select the properties of the Directory, Select Directory Security, IP

Address and domain name restrictions, select authorized access, click OK, or select deny access, add the IP address of your client computer to the exception.
Third, open the folder where the msadc virtual directory is located and you will find three Reg files. add them to the Registry.
Fourth, Start, Run, input iisreset, or directly restart the computer.

Return to the client and run the preceding VBProgramClick "command1" to connect to MSSQL through ODBC, and click "command2" to connect to the server

 

 

 

Related Article

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.