[转]vc连接access 数据库连接之Access数据库连接字符
2010-10-25 10:07
417 查看
Microsoft Jet OLE DB 4.0
Standard security:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;User Id=admin;Password=;
With database password:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;Jet OLEDB:Database Password=MyDbPassword;
Workgroup (system database):
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;Jet OLEDB:System Database=system.mdw;
Workgroup (system database) specifying username and password:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;Jet OLEDB:System Database=system.mdw;User ID=myUsername;Password=myPassword;
DataDirectory functionality:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/myDatabase.mdb;User Id=admin;Password=;
.NET Framework Data Provider for OLE DB
Bridging to Jet OLE DB 4.0:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;User Id=admin;Password=;
Microsoft Access ODBC Driver
Standard Security:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;
Workgroup:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;SystemDB=C:/mydatabase.mdw;
Exclusive:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Exclusive=1;Uid=admin;Pwd=;
Enable admin statements:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;ExtendedAnsiSQL=1;
Specifying locale identifier:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Locale Identifier=2057;Uid=Admin;Pwd=;
.NET Framework Data Provider for ODBC
Bridging to Microsoft Access ODBC Driver
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;
ADO数据库连接中的Persist Security Info参数的作用
ADO用了这么久,每次用向导创建ADO的数据库连接字符串时总会有产生一个Persist Security Info属性,平时没太注意,因为设置为True或False时对数据库连接没有任何影响。不过心理还是不爽,今天有时间查询了一下资料,总算搞清楚了它的作用。
Persist Security Info属性的意思是表示是否保存安全信息,其实可以简单的理解为"ADO在数据库连接成功后是否保存密码信息",
True表示保存,False表示不保存
ADO缺省为True
(ADO.net缺省为False,未测试,根据参考资料上说的)
具体可以通过ADO的Connect对象的ConnectString属性进行验证,如下所示(以下在Delphi7中测试通过):
----------------------------------------------------------------------------------------------------------
数据库连接前
ConnectString="Provider=MSDAORA.1;Password=mypassword;User ID=yzs;Data Source=ydgl22;Persist Security Info=false"
数据库连接成功后
ConnectString="Provider=MSDAORA.1;User ID=yzs;Data Source=ydgl22"
----------------------------------------------------------------------------------------------------------
数据库连接前
ConnectString="Provider=MSDAORA.1;Password=mypassword;User ID=yzs;Data Source=ydgl22;Persist Security Info=true"
数据库连接成功后
ConnectString="Provider=MSDAORA.1;Password=mypassword;User ID=dlyx;Data Source=ydgl22"
----------------------------------------------------------------------------------------------------------
总体来说,如果数据库连接成功后不再需要连接的密码,出于安全性考虑,还是建议将Persist Security Info设为false,以防止后门程序取得数据库连接的密码(windows2003在sp1前就发生过这个问题)。
ADO连接字符串归纳(oracle sqlserver mysql access)
2008-03-14 17:22
Overview
Generally, one of the first steps when you are trying to work with databases is open it. You can find several types of those, and each have a different mode of connection. When you try to connect with your database sometimes, you don't know the correct connection string that you must use. It is for that I wrote this article. I wanted to compile the connection strings to the majority of known databases...
ODBC DSN Less Connection
ODBC Driver for dBASE
strConnection = _T("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;" "Dbq=c://DatabasePath;");
Note: You must specify the filename in the SQL statement... For example:
CString strQuery = _T("Select Name, Address From Clients.dbf");
ODBC Driver for Excel
strConnection = _T("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;" bq=C://DatabasePath//DBSpreadSheet.xls;DefaultDir=c://databasepath;");
ODBC Driver for Text
strConnection = _T("Driver={Microsoft Text Driver (*.txt; *.csv)};" "Dbq=C://DatabasePath//;Extensions=asc,csv,tab,txt;");
If you are using tab delimited files, you must create the schema.ini file, and you must inform the Format=TabDelimited option in your connection string.
Note: You must specify the filename in the SQL statement... For example:
CString strQuery = _T("Select Name, Address From Clients.csv");
Visual FoxPro
If you are using a database container, the connection string is the following:
strConnection = _T("Driver={Microsoft Visual Foxpro Driver};UID=;" ourceType=DBC;SourceDB=C://DatabasePath//MyDatabase.dbc;Exclusive=No");
If you are working without a database container, you must change the SourceType parameter by DBF as in the following connection string:
strConnection = _T("Driver={Microsoft Visual Foxpro Driver};UID=;" "SourceType=DBF;SourceDB=C://DatabasePath//MyDatabase.dbc;Exclusive=No");
ODBC Driver for Access
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=c://DatabasePath//dbaccess.mdb;Uid=;Pwd=;");
If you are using a Workgroup (System database): you need to inform the SystemDB Path, the User Name and its password. For that, you have two solutions: inform the user and password in the connection string or in the moment of the open operation. For example:
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=C://VC Projects//ADO//Samples//AdoTest//dbTestSecurity.mdb;" "SystemDB=C://Program Files//Microsoft Office//Office//SYSTEM.mdw;" "Uid=Carlos Antollini;Pwd=carlos");
or may be:
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=C://VC Projects//ADO//Samples//AdoTest//dbTestSecurity.mdb;" "SystemDB=C://Program Files//Microsoft Office//Office//SYSTEM.mdw;"); if(pDB.Open(strConnection, "DatabaseUser", "DatabasePass")) { DoSomething(); pDB.Close(); }
If you want to open in Exclusive mode:
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=c://DatabasePath/dbaccess.mdb;Exclusive=1;");
ODBC Driver for SQL Server
For Standard security:
strConnection = _T("Driver={SQL Server};Server=MyServerName;" "Trusted_Connection=no;" "Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");
For Trusted Connection security (Microsoft Windows NT integrated security):
strConnection = _T("Driver={SQL Server};Server=MyServerName;" "Database=myDatabaseName;Uid=;Pwd=;");
Also, you can use the parameter Trusted_Connection that indicates that you are using the Microsoft Windows NT Authentication Mode to authorize user access to the SQL Server database. For example:
strConnection = _T("Driver={SQL Server};Server=MyServerName;" "Database=MyDatabaseName;Trusted_Connection=yes;");
If the SQL Server is running in the same computer, you can replace the name of the server by the word (local) like in the following sample:
strConnection = _T("Driver={SQL Server};Server=(local);" "Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");
If you want to connect with a remote SQL Server, you must inform the address, the port, and the Network Library to use:
The Address parameter must be an IP address and must include the port. The Network parameter can be one of the following:
dbnmpntw Win32 Named Pipes
dbmssocn Win32 Winsock TCP/IP
dbmsspxn Win32 SPX/IPX
dbmsvinn Win32 Banyan Vines
dbmsrpcn Win32 Multi-Protocol (Windows RPC)
For more information, see Q238949.
strConnection = _T("Driver={SQL Server};Server=130.120.110.001;" "Address=130.120.110.001,1052;Network=dbmssocn;Database=MyDatabaseName;" "Uid=myUsername;Pwd=myPassword;");
ODBC Driver for Oracle
For the current Oracle ODBC driver from Microsoft:
strConnect = _T("Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;" "Uid=MyUsername;Pwd=MyPassword;");
For the older Oracle ODBC driver from Microsoft:
strConnect = _T("Driver={Microsoft ODBC Driver for Oracle};" "ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;");
ODBC Driver for MySQL
If you want to connect to a local database, you can use a connection string like the following:
strConnect = _T("Driver={MySQL ODBC 3.51 Driver};Server=localhost;" "Database=MyDatabase;User=MyUserName;Password=MyPassword;Option=4;");
If you want to connect with a remote database, you need to specify the name of the server or its IP in the Server parameter. If the Port is distinct to 3306 (default port), you must specify it.
strConnect = _T("Driver={mySQL ODBC 3.51 Driver};Server=MyRemoteHost;" "Port=3306;Option=4;Database=MyDatabase;Uid=MyUsername;Pwd=MyPassword;");
Standard security:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;User Id=admin;Password=;
With database password:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;Jet OLEDB:Database Password=MyDbPassword;
Workgroup (system database):
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;Jet OLEDB:System Database=system.mdw;
Workgroup (system database) specifying username and password:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;Jet OLEDB:System Database=system.mdw;User ID=myUsername;Password=myPassword;
DataDirectory functionality:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/myDatabase.mdb;User Id=admin;Password=;
.NET Framework Data Provider for OLE DB
Bridging to Jet OLE DB 4.0:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/mydatabase.mdb;User Id=admin;Password=;
Microsoft Access ODBC Driver
Standard Security:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;
Workgroup:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;SystemDB=C:/mydatabase.mdw;
Exclusive:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Exclusive=1;Uid=admin;Pwd=;
Enable admin statements:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;ExtendedAnsiSQL=1;
Specifying locale identifier:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Locale Identifier=2057;Uid=Admin;Pwd=;
.NET Framework Data Provider for ODBC
Bridging to Microsoft Access ODBC Driver
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;
ADO数据库连接中的Persist Security Info参数的作用
ADO用了这么久,每次用向导创建ADO的数据库连接字符串时总会有产生一个Persist Security Info属性,平时没太注意,因为设置为True或False时对数据库连接没有任何影响。不过心理还是不爽,今天有时间查询了一下资料,总算搞清楚了它的作用。
Persist Security Info属性的意思是表示是否保存安全信息,其实可以简单的理解为"ADO在数据库连接成功后是否保存密码信息",
True表示保存,False表示不保存
ADO缺省为True
(ADO.net缺省为False,未测试,根据参考资料上说的)
具体可以通过ADO的Connect对象的ConnectString属性进行验证,如下所示(以下在Delphi7中测试通过):
----------------------------------------------------------------------------------------------------------
数据库连接前
ConnectString="Provider=MSDAORA.1;Password=mypassword;User ID=yzs;Data Source=ydgl22;Persist Security Info=false"
数据库连接成功后
ConnectString="Provider=MSDAORA.1;User ID=yzs;Data Source=ydgl22"
----------------------------------------------------------------------------------------------------------
数据库连接前
ConnectString="Provider=MSDAORA.1;Password=mypassword;User ID=yzs;Data Source=ydgl22;Persist Security Info=true"
数据库连接成功后
ConnectString="Provider=MSDAORA.1;Password=mypassword;User ID=dlyx;Data Source=ydgl22"
----------------------------------------------------------------------------------------------------------
总体来说,如果数据库连接成功后不再需要连接的密码,出于安全性考虑,还是建议将Persist Security Info设为false,以防止后门程序取得数据库连接的密码(windows2003在sp1前就发生过这个问题)。
ADO连接字符串归纳(oracle sqlserver mysql access)
2008-03-14 17:22
Overview
Generally, one of the first steps when you are trying to work with databases is open it. You can find several types of those, and each have a different mode of connection. When you try to connect with your database sometimes, you don't know the correct connection string that you must use. It is for that I wrote this article. I wanted to compile the connection strings to the majority of known databases...
ODBC DSN Less Connection
ODBC Driver for dBASE
strConnection = _T("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;" "Dbq=c://DatabasePath;");
Note: You must specify the filename in the SQL statement... For example:
CString strQuery = _T("Select Name, Address From Clients.dbf");
ODBC Driver for Excel
strConnection = _T("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;" bq=C://DatabasePath//DBSpreadSheet.xls;DefaultDir=c://databasepath;");
ODBC Driver for Text
strConnection = _T("Driver={Microsoft Text Driver (*.txt; *.csv)};" "Dbq=C://DatabasePath//;Extensions=asc,csv,tab,txt;");
If you are using tab delimited files, you must create the schema.ini file, and you must inform the Format=TabDelimited option in your connection string.
Note: You must specify the filename in the SQL statement... For example:
CString strQuery = _T("Select Name, Address From Clients.csv");
Visual FoxPro
If you are using a database container, the connection string is the following:
strConnection = _T("Driver={Microsoft Visual Foxpro Driver};UID=;" ourceType=DBC;SourceDB=C://DatabasePath//MyDatabase.dbc;Exclusive=No");
If you are working without a database container, you must change the SourceType parameter by DBF as in the following connection string:
strConnection = _T("Driver={Microsoft Visual Foxpro Driver};UID=;" "SourceType=DBF;SourceDB=C://DatabasePath//MyDatabase.dbc;Exclusive=No");
ODBC Driver for Access
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=c://DatabasePath//dbaccess.mdb;Uid=;Pwd=;");
If you are using a Workgroup (System database): you need to inform the SystemDB Path, the User Name and its password. For that, you have two solutions: inform the user and password in the connection string or in the moment of the open operation. For example:
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=C://VC Projects//ADO//Samples//AdoTest//dbTestSecurity.mdb;" "SystemDB=C://Program Files//Microsoft Office//Office//SYSTEM.mdw;" "Uid=Carlos Antollini;Pwd=carlos");
or may be:
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=C://VC Projects//ADO//Samples//AdoTest//dbTestSecurity.mdb;" "SystemDB=C://Program Files//Microsoft Office//Office//SYSTEM.mdw;"); if(pDB.Open(strConnection, "DatabaseUser", "DatabasePass")) { DoSomething(); pDB.Close(); }
If you want to open in Exclusive mode:
strConnection = _T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=c://DatabasePath/dbaccess.mdb;Exclusive=1;");
ODBC Driver for SQL Server
For Standard security:
strConnection = _T("Driver={SQL Server};Server=MyServerName;" "Trusted_Connection=no;" "Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");
For Trusted Connection security (Microsoft Windows NT integrated security):
strConnection = _T("Driver={SQL Server};Server=MyServerName;" "Database=myDatabaseName;Uid=;Pwd=;");
Also, you can use the parameter Trusted_Connection that indicates that you are using the Microsoft Windows NT Authentication Mode to authorize user access to the SQL Server database. For example:
strConnection = _T("Driver={SQL Server};Server=MyServerName;" "Database=MyDatabaseName;Trusted_Connection=yes;");
If the SQL Server is running in the same computer, you can replace the name of the server by the word (local) like in the following sample:
strConnection = _T("Driver={SQL Server};Server=(local);" "Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");
If you want to connect with a remote SQL Server, you must inform the address, the port, and the Network Library to use:
The Address parameter must be an IP address and must include the port. The Network parameter can be one of the following:
dbnmpntw Win32 Named Pipes
dbmssocn Win32 Winsock TCP/IP
dbmsspxn Win32 SPX/IPX
dbmsvinn Win32 Banyan Vines
dbmsrpcn Win32 Multi-Protocol (Windows RPC)
For more information, see Q238949.
strConnection = _T("Driver={SQL Server};Server=130.120.110.001;" "Address=130.120.110.001,1052;Network=dbmssocn;Database=MyDatabaseName;" "Uid=myUsername;Pwd=myPassword;");
ODBC Driver for Oracle
For the current Oracle ODBC driver from Microsoft:
strConnect = _T("Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;" "Uid=MyUsername;Pwd=MyPassword;");
For the older Oracle ODBC driver from Microsoft:
strConnect = _T("Driver={Microsoft ODBC Driver for Oracle};" "ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;");
ODBC Driver for MySQL
If you want to connect to a local database, you can use a connection string like the following:
strConnect = _T("Driver={MySQL ODBC 3.51 Driver};Server=localhost;" "Database=MyDatabase;User=MyUserName;Password=MyPassword;Option=4;");
If you want to connect with a remote database, you need to specify the name of the server or its IP in the Server parameter. If the Port is distinct to 3306 (default port), you must specify it.
strConnect = _T("Driver={mySQL ODBC 3.51 Driver};Server=MyRemoteHost;" "Port=3306;Option=4;Database=MyDatabase;Uid=MyUsername;Pwd=MyPassword;");
相关文章推荐
- VC++ ado连接数据库(可以在VC6.0使用,以access数据库为实例)(1)
- 如何获得vc中连接access类型数据库的连接字符串?
- VC采用COM技术连接数据库(ACCESS)
- VC++之数据库连接Access
- VC 在WIN7下使用ADO方式连接ACCESS数据库到XP不能运行
- 连接数据库-----Access,SQL Server,Oracle,MySQL,IBM DB2,SyBase各数据库连接方法
- Java JDBC连接数据库 Access连接数据库
- vc++中ADO连接数据库
- vc连接数据库SQL SEVER必须要的那几把斧头
- vc中字符日期到数据库日期的转化
- Matlab连接数据库ACCESS数据库
- c# 连接access在web.config中的连接数据库语句
- JDBC连接数据库工具类及连接Access数据库示例
- Java JDBC连接数据库 Access连接数据库
- access数据库:怎么直接从access里把数据里同样的文字替换成空字符""
- asp.net 连接access 数据库时要安装的组件
- 在 web.config 中保存数据库连接字段ACCESS
- VC编写ADO连接Access,SQL Server数据库入门实例
- ASP.NET数据库编程之Access连接失败