[转]vc连接access 数据库连接之Access数据库连接字符

   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;");

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值