欢迎光临
我们一直在努力

ADO连接数据库字符串大全(VP,Excel,文本,Sybase,.NET等)-ASP教程,数据库相关

建站超值云服务器,限时71元/月

ado连接数据库字符串大全(vp,excel,文本,sybase,.net等)

this page contains sample ado connection strings for odbc dsn / dsn-less,

ole db providers, remote data services (rds), ms remote, ms datashape.

also included are ado.net connection strings for each .net managed provider

(sqlclient, oledb, and odbc).

these sample connection strings are compiled

by carl prothman, a microsoft visual basic mvp

enjoy!

 

table of contents

odbc dsn connections dsn

file dsn

odbc dsn-less connections  odbc driver for as/400

odbc driver for access

odbc driver for dbase

odbc driver for excel

odbc driver for mysql

odbc driver for oracle

odbc driver for paradox

odbc driver for sql server

odbc driver for sybase

odbc driver for sybase sql anywhere

odbc driver for text

odbc driver for teradata

odbc driver for visual foxpro

ole db data link connections data link file (udl)

ole db data provider connections  ole db provider for as/400

ole db provider for active directory service

ole db provider for db2

old db provider for internet publishing

ole db provider for index server

ole db provider for microsoft jet

ole db provider for odbc databases

ole db provider for oracle (from microsoft)

ole db provider for oracle (from oracle)

ole db provider for simple provider

ole db provider for sql server

remote data service (rds) connections rds data control – connect property

rds data control – url property

ado url connections ado recordset

ms remote provider connections ms remote – access (jet)

ms remote – sql server

data shape provider connections  ms datashape – sql server

.net managed provider connections sql client .net managed provider (system.data.sqlclient)

ole db .net managed provider (system.data.oledb)

odbc .net managed provider (system.data.odbc)

 

odbc dsn connections

using an odbc dsn (data source name) is a two step process.

1) you must first create the dsn via the "odbc data source administrator" program

found in your computers control panel (or administrative tools menu in windows 2000).

make sure to create a system dsn (not a user dsn) when using asp.

note: you can also create the dsn via vb code.

2) then use the following connection string – with your own dsn name of course.  😉

odbc – dsn

 

oconn.open "dsn=advworks;" & _

          "uid=admin;" & _

          "pwd=;

you can also create and use a file dsn. then use the following ado connection string:

odbc – file dsn

 

oconn.open "filedsn=c:\somepath\mydb.dsn;" & _

          "uid=admin;" & _

          "pwd=;"

for more information, see: about odbc data sources and

how to use file dsns and dsn-less connections

note: the problem with dsn is that users can (and will) modify them (or delete by mistake),

then your program wont work so well… so its better to use a dsn-less or ole db provider

connection string with a trusted connection if possible!

odbc dsn-less connections

odbc driver for as/400

 

oconn.open "driver={client access odbc driver (32-bit)};" & _

          "system=myas400;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

for more information, see:  a fast path to as/400 client/server

odbc driver for access

 

for standard security:

oconn.open "driver={microsoft access driver (*.mdb)};" & _

          "dbq=c:\somepath\mydb.mdb;" & _

          "uid=admin;" & _

          "pwd=;"

if you are using a workgroup (system database):

oconn.open "driver={microsoft access driver (*.mdb)};" & _

          "dbq=c:\somepath\mydb.mdb;" & _

          "systemdb=c:\somepath\mydb.mdw;", _

          "admin", ""

if mdb is located on a network share:

oconn.open "driver={microsoft access driver (*.mdb)};" & _

          "dbq=\\myserver\myshare\mypath\mydb.mdb;"

for more information, see: microsoft access driver programming considerations

odbc driver for dbase

 

oconn.open "driver={microsoft dbase driver (*.dbf)};" & _

         "driverid=277;" & _

         "dbq=c:\somepath;"

note: specify the filename in the sql statement. for example:

     ors.open "select * from user.dbf", oconn, , ,adcmdtext

note: mdac 2.1 (or greater) requires the borland database engine (bde) to update dbase dbf files. (q238431).

for more information, see: dbase driver programming considerations

odbc driver for excel

 

oconn.open "driver={microsoft excel driver (*.xls)};" & _

          "driverid=790;" & _

          "dbq=c:\somepath\myspreadsheet.xls;" & _

          "defaultdir=c:\somepath;"

for more information, see: microsoft excel driver programming considerations

odbc driver for mysql (via myodbc)

 

to connect to a local database

oconn.open "driver={mysql};" & _

          "server=myservername;" & _

          "option=16834;" & _

          "database=mydb;"

to connect to a remote database

oconn.open "driver={mysql};" & _

          "server=db1.database.com;" & _

          "port=3306;" & _

          "option=131072;" & _

          "stmt=;" & _

          "database=mydb;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

for more information, see: programs known to work with myodbc

odbc driver for oracle

 

for the current oracle odbc driver from microsoft:

oconn.open "driver={microsoft odbc for oracle};" & _

          "server=oracleserver.world;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

for the older oracle odbc driver from microsoft:

oconn.open "driver={microsoft odbc driver for oracle};" & _

          "connectstring=oracleserver.world;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

for more information, see: connection string format and attributes

odbc driver for paradox

 

oconn.open "driver={microsoft paradox driver (*.db)};" & _

          "driverid=538;" & _

          "fil=paradox 5.x;" & _

          "defaultdir=c:\dbpath\;" & _

          "dbq=c:\dbpath\;" & _

          "collatingsequence=ascii;"

note: mdac 2.1 (or greater) requires the borland database engine (bde) to update paradox isam fdbf files. (q230126).

for more information, see: paradox driver programming considerations

odbc driver for sql server

 

for standard security:

oconn.open "driver={sql server};" & _

          "server=myservername;" & _

         "database=mydatabasename;" & _

         "uid=myusername;" & _

          "pwd=mypassword;"

for trusted connection security:

oconn.open "driver={sql server};" & _

          "server=myservername;" & _

          "database=mydatabasename;" & _

          "uid=;" & _

          "pwd=;"

or

oconn.open "driver={sql server};" & _

          "server=myservername;" & _

          "database=mydatabasename;" & _

          "trusted_connection=yes;"

to prompt user for username and password

oconn.properties("prompt") = adpromptalways

oconn.open "driver={sql server};" & _

          "server=myservername;" & _

          "database=mydatabasename;"

  

for more information, see: sqldriverconnect (odbc)

odbc driver for sybase

 

if using the sybase system 11 odbc driver:

oconn.open "driver={sybase system 11};" & _

          "srvr=myservername;" & _

         "uid=myusername;" & _

          "pwd=mypassword;"

if using the intersolv 3.10 sybase odbc driver:

oconn.open "driver={intersolv 3.10 32-bit sybase};" & _

          "srvr=myservername;" & _

         "uid=myusername;" & _

          "pwd=mypassword;"

for more information, see: sybase system 10 odbc driver reference guide

odbc driver for sybase sql anywhere

 

oconn.open "odbc; driver=sybase sql anywhere 5.0;" & _

          "defaultdir=c:\dbpath\;" & _

          "dbf=c:\sqlany50\mydb.db;" & _

         "uid=myusername;" & _

          "pwd=mypassword;"

          "dsn="""";"

note: including the dsn tag with a null string is absolutely critical or else you get the dreaded -7778 error.

for more information, see: sybase sql anywhere user guide

odbc driver for teradata

 

oconn.open "provider=teradata;" & _

          "dbcname=mydbcname;" & _

          "database=mydatabasename;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

for more information, see teradata odbc driver

odbc driver for text

 

oconn.open "driver={microsoft text driver (*.txt; *.csv)};" & _

          "dbq=c:\somepath\;" & _

          "extensions=asc,csv,tab,txt;" & _

          "persist security info=false"

note: specify the filename in the sql statement. for example:

ors.open "select * from customer.csv", _

        oconn, adopenstatic, adlockreadonly, adcmdtext

for more information, see: text file driver programming considerations

odbc driver for visual foxpro

 

with a database container:

oconn.open "driver={microsoft visual foxpro driver};" & _

          "sourcetype=dbc;" & _

          "sourcedb=c:\somepath\mysourcedb.dbc;" & _

          "exclusive=no;"

without a database container (free table directory):

oconn.open "driver={microsoft visual foxpro driver};" & _

          "sourcetype=dbf;" & _

          "sourcedb=c:\somepath\mysourcedbfolder;" & _

          "exclusive=no;"

for more information, see: visual foxpro odbc driver and q165492

ole db data link connections

data link file (udl)

 

for absolute path:

oconn.open "file name=c:\somepath\mydatabasename.udl;"

for relative path:

oconn.open "file name=mydatabasename.udl;"

 

for more information, see: howto: use data link files with ado

note: windows 2000 no longer contains the "new | microsoft data link" menu 

anymore. you can add the data link menu back in the menu list by running the

"c:\program files\common files\system\ole db\newudl.reg" reg file,

then right-click on the desktop and select "new | microsoft data link" menu. 

or you can also create a data link file by creating a text file and change its

file extension to ".udl", then double-click the file.

ole db provider connections

ole db provider for as/400

 

oconn.open "provider=ibmda400;" & _

          "data source=myas400;"

          "user id=myusername;" & _

          "password=mypassword;"

for more information, see:  a fast path to as/400 client/server

ole db provider for active directory service

 

oconn.open "provider=adsdsoobject;" & _

          "user id=myusername;" & _

          "password=mypassword;"

 

for more information, see: microsoft ole db provider for microsoft active directory service

ole db provider for db2

 

oconn.open = "provider=db2oledb;" &

           "network transport library=tcpip;" &

           "network address=myserver;" & _

           "package collection=mypackage;" &

           "host ccsid=1142"

           "initial catalog=mydb;" &

           "user id=myusername;" & _

           "password=mypassword;"

for more information, see: ole db provider for db2

and inf: configuring data sources for the microsoft ole db provider for db2

ole db provider for index server

 

oconn.open "provider=msidxs;" & _

          "data source=mycatalog;"

 

for more information, see: microsoft ole db provider for microsoft indexing service

ole db provider for internet publishing

 

oconn.open "provider=msdaipp.dso;" & _

      "data source=http://mywebsite/mydir;" & _

      "user id=myusername;" & _

      "password=mypassword;"

 

for more information, see: microsoft ole db provider for internet publishing and q245359

ole db provider for microsoft jet

 

for standard security:

oconn.open "provider=microsoft.jet.oledb.4.0;" & _

          "data source=c:\somepath\mydb.mdb;" & _

          "user id=admin;" & _

          "password=;"

if using a workgroup (system database):

oconn.open "provider=microsoft.jet.oledb.4.0;" & _

          "data source=c:\somepath\mydb.mdb;" & _

          "jet oledb:system database=mysystem.mdw;", _

          "admin", ""

note, remember to convert both the mdb and the mdw to the 4.0 database format when using the 4.0 ole db provider.

if mdb has a database password:

oconn.open "provider=microsoft.jet.oledb.4.0;" & _

          "data source=c:\somepath\mydb.mdb;" & _

          "jet oledb:database password=mydbpassword;", _

          "admin", ""

if mdb is located on a network share:

oconn.open "provider=microsoft.jet.oledb.4.0;" & _

          "data source=\\myserver\myshare\mypath\mydb.mdb;

if want to open up the access database exclusively:

oconn.mode = admodeshareexclusive

oconn.open "provider=microsoft.jet.oledb.4.0;" & _

          "data source=c:\somepath\mydb.mdb;" & _

          "user id=admin;" & _

          "password=;"

for more information, see: ole db provider for microsoft jet, q191754, q225048, q239114, and q271908

you can also open an excel spreadsheet using the "ole db provider for microsoft jet"

oconn.open "provider=microsoft.jet.oledb.4.0;" & _

          "data source=c:\somepath\myexcelspreadsheet.xls;" & _

          "extended properties=""excel 8.0;hdr=yes;"";"

where "hdr=yes" means that there is a header row in the cell range

(or named range), so the provider will not include the first row of the

selection into the recordset. if "hdr=no", then the provider will include

the first row of the cell range (or named ranged) into the recordset.

for more information, see: q278973

you can also open a text file using the "ole db provider for microsoft jet"

oconn.open "provider=microsoft.jet.oledb.4.0;" & _

          "data source=c:\somepath\;" & _

          "extended properties=""text;hdr=yes;fmt=delimited;"";"

then open a recordset based on a select on the actual file

ors.open "select * from mytextfile.txt", oconn, adopenstatic, adlockreadonly, adcmdtext

for more information, see: q262537

ole db provider for odbc databases

 

for access (jet):

oconn.open "provider=msdasql;" & _

          "driver={microsoft access driver (*.mdb)};" & _

          "dbq=c:\somepath\mydb.mdb;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

for sql server:

oconn.open "provider=msdasql;" & _

          "driver={sql server};" & _

          "server=myservername;" & _

          "database=mydatabasename;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

for more information, see: microsoft ole db provider for odbc

ole db provider for oracle (from microsoft)

 

oconn.open "provider=msdaora;" & _

          "data source=myoracledb;" & _

          "user id=myusername;" & _

          "password=mypassword;"

for more information, see: microsoft ole db provider for oracle

ole db provider for oracle (from oracle)

 

for standard security:

oconn.open "provider=oraoledb.oracle;" & _

          "data source=myoracledb;" & _

          "user id=myusername;" & _

          "password=mypassword;"

for a trusted connection:

oconn.open "provider=oraoledb.oracle;" & _

          "data source=myoracledb;" & _

          "user id=/;" & _

          "password=;"

or

oconn.open "provider=oraoledb.oracle;" & _

          "data source=myoracledb;" & _

          "osauthent=1;"

 

note: "data source=" must be set to the appropriate net8 name which is known to the naming method in use. for example, for local naming, it is the alias in the tnsnames.ora file; for oracle names, it is the net8 service name.

for more information, see: connecting to an oracle database

(note, if you get a logon dialog, then click cancel, then perform a one-time free signup with oracles technet system)

ole db provider for simple provider

 

the microsoft ole db simple provider (osp) allows ado to access any data for which a provider has

been written using the ole db simple provider toolkit. simple providers are intended to access data

sources that require only fundamental ole db support, such as in-memory arrays or xml documents.

osp in mdac 2.6 has been enhanced to support opening hierarchical ado recordsets over arbitrary

xml files. these xml files may contain the ado xml persistence schema, but it is not required. this

has been implemented by connecting the osp to the msxml2.dll, therefore msxml2.dll or newer is

required.

oconn.open "provider=msdaosp;" & _

          "data source=msxml2.dsocontrol.2.6;"

ors.open "http://webserver/virtualroot/myxmlfile.xml", oconn

for more information, see: microsoft ole db simple provider

ole db provider for sql server

 

for standard security:

oconn.open "provider=sqloledb;" & _

          "data source=myservername;" & _

          "initial catalog=mydatabasename;" & _

          "user id=myusername;" & _

          "password=mypassword;"

for a trusted connection:

oconn.open "provider=sqloledb;" & _

          "data source=myservername;" & _

          "initial catalog=mydatabasename;" & _

          "integrated security=sspi;"

to connect to a "named instance" (sql server 2000)

oconn.open "provider=sqloledb;" & _

          "data source=myservername\inst2;" & _

          "initial catalog=mydatabasename;" & _

          "user id=myusername;" & _

          "password=mypassword;"

to prompt user for username and password:

oconn.provider = "sqloledb"

oconn.properties("prompt") = adpromptalways

oconn.open "data source=myservername;" & _

          "initial catalog=mydatabasename;"

to connect via an ip address:

oconn.open "provider=sqloledb;" & _

          "data source=xxx.xxx.xxx.xxx,1433;" & _

          "network library=dbmssocn;" & _

          "initial catalog=mydatabasename;" & _

          "user id=myusername;" & _

          "password=mypassword;"

note:

– xxx.xxx.xxx.xxx is an ip address

– "network library=dbmssocn" tells ole db to use tcp/ip rather than named pipes (q238949)

– 1433 is the default port number for sql server

– you can also add "encrypt=yes" for encryption

for more information, see: microsoft ole db provider for sql server

remote data service (rds) connections

the following examples show how to connect to a remote database using the rds data control.

when using the rds datacontrols server/sql/connect properties, the rds datacontrol uses the

rds datafactory on the remote server. if you use the rds datacontrols url property,

then the rds datafactory is not used at all.

warning: the rds datafactory can be a major security hole if not setup and configured correctly!

for more information, see rds faq #24

rds datacontrol – connect property

 

with the rds default handler disabled (not recommend due to security risks):

with ordc

  .server = "http://carl2"

  .sql = "select * from authors where state = ca"

  .connect = "provider=sqloledb;" & _

           "data source=(local);" & _

           "initial catalog=pubs;" & _

           "user id=sa;" & _

           "password=;"

  .refresh

end with

with the rds default handler enabled (recommend):

with ordc

  .server = "http://carl2"

  .handler = "msdfmap.handler"

  .connect = "data source=myconnecttag;"

  .sql = "mysqltag(""ca"")"

  .refresh

end with

the corresponding connect and sql sections in the default handler \winnt\msdfmap.ini file would be:

[connect myconnecttag]

access = readwrite

connect = "provider=sqloledb;data source=(local);initial catalog=pubs;user id=sa;password=;"

[sql mysqltag]

sql = "select * from authors where state = ?"

for more information about the rds default handler, see:

q243245, q230680, and rds customization handler microsoft articles

rds datacontrol – url property

 

to get records from a remote database:

with ordc

  .url = "http://carlp0/authors_getbystate.asp?state=ca"

  .refresh

end with

to save, set the url property to an asp web page:

with ordc

  .url = "http://carlp0/rdsdatacontrol/authors_save.asp"

  .submitchanges

end with

for more information, see: rds url property

ado url connections

ado 2.5+ allows you to open up a recordset based on xml returned from an asp file over http. 

this feature doesnt use rds at all.

ado recordset

 

to get records from a remote database:

ors.open "http://carlp0/authors_getbystate.asp?state=ca", , _

                      adopenstatic, adlockbatchoptimistic

to save changes, you must use the msxmls xmlhttp object to post back the updated xml. 

the recordsets update and updatebatch methods will not work in this case.

save recordset into stream

set ostm = new adodb.stream

ors.save ostm, adpersistxml

use msxmls xmlhttp object to open asp and post a xml stream

set oxmlhttp = new msxml2.xmlhttp30

oxmlhttp.open "post", "http://carlp0/authors_save.asp", false

oxmlhttp.send ostm.readtext

if an error occurred

if oxmlhttp.status = 500 then

  debug.print oxmlhttp.statustext

end if

for more information, see: ado recordsets open method

ms remote provider connections

the following connections strings use microsofts remote provider (ms remote). the ms remote

provider tells ado to communicate with the remote server (via the rds datafactory) and to use

the remote provider that is installed on the remote server.

warning: the rds datafactory can be a major security hole if not setup and configured correctly! 

for more information, see rds faq #24

  

ms remote – access (jet)

 

if you want to use an odbc dsn on the remote machine:

oconn.open "provider=ms remote;" & _

          "remote server=http://myservername;" & _

          "remote provider=msdasql;" & _

          "dsn=advworks;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

if you want to use an ole db provider on the remote machine:

oconn.open "provider=ms remote;" & _

          "remote server=http://myservername;" & _

          "remote provider=microsoft.jet.oledb.4.0;" & _

          "data source=c:\somepath\mydb.mdb;", _

          "admin", ""

if you want to use an ole db provider on the remote machine (via rds datafactory default handler):

oconn.open "provider=ms remote;" & _

          "remote server=http://myservername;" & _

          "handler=msdfmap.handler;" & _

          "data source=myadvworksconn;"

the corresponding entry in the \winnt\msdfmap.ini file would be:

[connect myadvworksconn]

access = readwrite

connect = "provider=microsoft.jet.oledb.4.0;" & _

        "data source=mydb.mdb;" & _

        "user id=admin;" & _

        "password=;"

 

ms remote – sql server

 

if you want to use an odbc dsn on the remote machine:

oconn.open "provider=ms remote;" & _

          "remote server=http://myservername;" & _

          "remote provider=msdasql;" & _

          "dsn=mydatabasename;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

if you want to use an ole db provider on the remote machine:

oconn.open "provider=ms remote;" & _

          "remote server=http://myservername;" & _

          "remote provider=sqloledb;" & _

         "data source=myservername;" & _

         "initial catalog=mydatabasename;" & _

         "user id=myusername;" & _

          "password=mypassword;"

if you want to use an ole db provider on the remote machine (via rds datafactory default handler):

oconn.open "provider=ms remote;" & _

          "remote server=http://myservername;" & _

          "handler=msdfmap.handler;" & _

          "data source=mypubsconn;"

the corresponding entry in the \winnt\msdfmap.ini file would be:

[connect mypubsconn]

access = readwrite

connect = "provider=sqloledb;" & _

        "data source=myservername;" & _

        "initial catalog=mydatabasename;" & _

        "user id=myusername;" & _

        "password=mypassword;"

for more information, see: microsoft ole db remoting provider  and q240838

data shape provider connections

ms datashape – sql server

 

oconn.open "provider=msdatashape;" & _

          "data provider=sqloledb;" & _

          "data source=mysqlservername;" & _

          "initial catalog=mydatabase;" & _

          "user id=myusername;" & _

          "password=mypassword;"

then use a shape command with sql strings:

ssql = "shape {select * from authors} " & _

      "append ({select * from titleauthor} as chapter " & _

      "relate au_id to au_id)"

or use a shape command that calls stored procedures:

ssql = "shape {exec spauthors_loadall} " & _

      "append ({exec sptitleauthor_loadall} as chapter " & _

      "relate au_id to au_id)"

for more information, see: microsoft data shaping service for ole db and q288409

.net managed provider connections

sql client .net managed provider (system.data.sqlclient)

 

the sql client .net managed provide allows you to connect to a microsoft sql server 7.0

or 2000 database. for microsoft sql server 6.0 or earlier, use the ole db .net data provider

with the "sql server ole db provider" (sqloledb).

dim osqlconnection as sqlclient.sqlconnection

dim sconnstring as string

sconnstring = "data source=(local);" & _

           "initial catalog=northwind;" & _

           "integrated security=sspi;" & _

           "pooling=true;" & _

           "min pool size=10;" & _

           "max pool size=50;" & _

           "connection lifetime=30;" & _

           "connection reset=true;" & _

           "enlist=true;"

osqlconnection = new sqlclient.sqlconnection(sconnstring)

osqlconnection.open()

for more information, see: system.data.sql namespace and .net data providers

note: sql namespace got renamed to sqlclient

ole db .net managed provider (system.data.oledb)

 

the ole db .net data provider uses native ole db through com interop to enable data access. 

to use the ole db .net data provider, you must also use an ole db provider (e.g. sqloledb,

msdaora, or microsoft.jet.oledb.4.0).

for sql server ole db provider (for sql server 6.0 or earlier)

dim ooledbconnection as oledb.oledbconnection

dim sconnstring as string

sconnstring = "provider=sqloledb;" & _

           "data source=myservername;" & _

           "initial catalog=mydatabasename;" & _

           "user id=myusername;" & _

          "password=mypassword;"

ooledbconnection = new oledb.oledbconnection(sconnstring)

ooledbconnection.open()

for jet ole db provider:

dim ooledbconnection as oledb.oledbconnection

dim sconnstring as string

sconnstring = "provider=microsoft.jet.oledb.4.0;" & _

           "data source=c:\work\nwind.mdb;" & _

           "user id=admin;" & _

           "password="";"

ooledbconnection = new oledb.oledbconnection(sconnstring)

ooledbconnection.open()

for more information, see: system.data.oledb namespace and .net data providers

note: ado namespace got renamed to oledb

odbc .net managed provider (system.data.odbc)

 

the odbc .net data provider is an add-on component to the .net framework sdk beta 2.

it provides access to native odbc drivers the same way the ole db .net data provider

provides access to native ole db providers.

for sql server odbc driver:

dim oodbcconnection as odbc.odbcconnection

dim sconnstring as string

create and open a new odbc connection

sconnstring = "driver={sql server};" & _

           "server=mysqlservername;" & _

           "database=mydatabasename;" & _

           "uid=myusername;" & _

           "pwd=mypassword;"

oodbcconnection = new odbc.odbcconnection(sconnstring)

oodbcconnection.open()

for oracle odbc driver:

dim oodbcconnection as odbc.odbcconnection

dim sconnstring as string

create and open a new odbc connection

sconnstring = "driver={microsoft odbc for oracle};" & _

          "server=oracleserver.world;" & _

          "uid=myusername;" & _

          "pwd=mypassword;"

oodbcconnection = new odbc.odbcconnection(sconnstring)

oodbcconnection.open()

for access (jet) odbc driver:

dim oodbcconnection as odbc.odbcconnection

dim sconnstring as string

create and open a new odbc connection

sconnstring = "driver={microsoft access driver (*.mdb)};" & _

          "dbq=c:\somepath\mydb.mdb;" & _

          "uid=admin;" & _

          "pwd=;"

oodbcconnection = new odbc.odbcconnection(sconnstring)

oodbcconnection.open()

for all other odbc drivers:

dim oodbcconnection as odbc.odbcconnection

dim sconnstring as string

create and open a new odbc connection

sconnstring = "dsn=mydsn;" & _

           "uid=myusername;" & _

           "pwd=mypassword;"

oodbcconnection = new odbc.odbcconnection(sconnstring)

oodbcconnection.open()

—-end—-

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ADO连接数据库字符串大全(VP,Excel,文本,Sybase,.NET等)-ASP教程,数据库相关
分享到: 更多 (0)