access数据库连接

这是一些我用来连接三种数据库的vba代码。

“ somefunctioncall”函数利用“ opendb”函数连接到数据库...

您将必须在后一个函数中输入参数,并取消注释“首选连接字符串”

您可能对此代码有些摆弄,但它应该可以工作...我通过谷歌搜索“连接字符串”使这些字符串脱离了网络...

这些数据库不必位于同一台PC上,只要您可以访问它们,它们就可以位于任何服务器上。

[2014-09-27:z:每个OP请求,随后是修改的代码块]


Public Function opendb() As ADODB.Connection
' This function returns an ADODB.Connection object
' which is required for accessing different types of databases
'
' Her we declare three strings to access database other than MS Access files on your network
' as it was in my case
Dim ORACLE_ConnString As String
Dim SQL_ConnString As String
Dim MSACCESS_ConnString As String
'*****************************************************************
' This variable is used only when accessing a MS Access database
' NOTE: I always keep the form separate from the database when using Access for Database and front end forms
Dim MSAdbPathAndName As String
MSAdbPathAndName = "C:\Reports\Database\msaccessdatabase.mdb"
'Probably could use a MapPath function here ...
'*****************************************************************
Dim DBN As String ' "DATABASENAME"
Dim UID As String '"yourusername"
Dim PWD As String '"yourPASSWORD"
Dim DBS As String '"SERVERNAME"
'Here is where you want to set your parameters for connecting to the desired database
DBS = "thisismywebservername"
UID = "thisisme"
PWD = "thisismypassword"
DBN = "thisismydbname"
'The connection strings are different for each type of database and network setup
ORACLE_ConnString = "Provider=msdaora;Data Source=" & DBN & _
";User Id=" & UID & ";Password=" & PWD & ";"
SQL_ConnString = "Provider=SQLOLEDB;DATA SOURCE=" & DBS & _
";UID=" & UID & _
";PWD=" & PWD & _
";Initial Catalog=" & DBN & ";"
MSACCESS_ConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
MSAdbPathAndName & ";"
'Here we declare and set the ADODB.Connection
opendb = New ADODB.Connection
'And finally you must decide which type of connection you are going to use... only one :)
'    *************** preferred connection string ***********
'    UNCOMMENT the ONE you need: if you want to connect to MS SQL then SQL_ConnString is the one you want
'    *******************************************************
'    opendb.Open ORACLE_ConnString
opendb.Open(SQL_ConnString)
'    opendb.Open MSACCESS_ConnString
End Function
Public Function stringReturningFunctionCall() As String
' The connection object is required for accessing the database and must be declared
Dim objConn As ADODB.Connection
' The  recordset object is required for storing the queried dataset and must be declared
Dim recSet As ADODB.Recordset
'This functioncal return a string, we declare and set it to be empty
Dim stringToReturn As String
stringToReturn = ""
'setting the connection object from a function that returns an ADODB.Connection
objConn = opendb
'setting the Recordset object using the Connection object to excute the SQL statement
recSet = objConn.Execute("SELECT [field1],[field2],[field3] FROM [sometable] order by [somefield] ")
Do While Not rs.EOF ' run through the recordset until at the end
'add your own code here
stringToReturn = someStringAppendingFunction(stringToReturn, recSet(0) & _
";" & recSet("field2") & _
";" & recSet("field3"), ";")
recSet.MoveNext()
Loop
'clean up time
objConn.Close()
objConn = Nothing
recSet = Nothing
'return the result
stringReturningFunctionCall = stringToReturn
End Function

翻译自: https://bytes.com/topic/access/insights/917619-connecting-different-databases-ms-access

access数据库连接

access数据库连接_从MS Access连接到不同的数据库相关推荐

  1. access全局变量_在MS Access中使用“全局”变量

    access全局变量 As developers, we frequently need to store values for use throughout our application or t ...

  2. access排名_在Microsoft Access中对行进行排名

    access排名 This is the third article on row numbers in Microsoft Access. 这是有关Microsoft Access中行号的第三篇文章 ...

  3. tableau无法建立连接_的Tableau错误连接到本地MySQL数据库

    Windows Server 2008的 的Tableau桌面7.0 本地MySQL使用XAMPP的Tableau错误连接到本地MySQL数据库 当试图使用的Tableau Desktop中的原生My ...

  4. cmd控制台连接MySQL数据库_如何利用CMD连接本机mysql数据库

    从事数据工作的IT人员,很多人都会与Mysql数据库打交道.因为mysql数据库是一个开源的数据库,利用它来学习数据库的人也有很多.笔者今天就给大家分享一下,安装好mysql之后,怎么利用CMD连接本 ...

  5. odbc数据库access丢失_有关使用access数据库,odbc中碰到的一些问题。

    年前写的一个j2ee小项目,数据库用的access,生产环境是在本机,xp,office2003 连接参数如下: driverName=sun.jdbc.odbc.JdbcOdbcDriver url ...

  6. token 微信access 过期_微信开发ACCESS TOKEN 过期失效解决方案

    微信开发-ACCESS TOKEN 过期失效解决方案 起因:因为access_token的重要性,开发过微信的都知道,但是他有自己的生命周期,官方解释为:"有效期为7200秒",一 ...

  7. java代码连接oracle数据库连接_在JAVA中连接Oracle数据库(例子)

    * TODO 要更改此生成的文件的模板,请转至 * 窗口 - 首选项 - java - 代码样式 - 代码模板 */ package person.fane.test; import java.sql ...

  8. .net mysql和php mysql数据库连接_浅谈PHP连接MySQL数据库的三种方式

    本篇文章给大家介绍一下PHP连接MySQL数据库的三种方式(mysql.mysqli.pdo),结合实例形式分析了PHP基于mysql.mysqli.pdo三种方式连接MySQL数据库的相关操作技巧与 ...

  9. docker登录mysql数据库_从docker容器连接到远程MySQL数据库

    我正在努力将一个Django 1.5.x应用程序容器化,该应用程序通过ODBC连接到单独服务器上的 MySQL数据库: [mysql_default] database = DB_NAME drive ...

最新文章

  1. 二代测序组装PK三代测序组装
  2. 25元、264KB内存的微处理器,树莓派官方出品,自带快速休眠模式
  3. python123第三章作业答案_swift playground类似的游戏
  4. js 数字千分位展示
  5. IDEA 启动、编译、clean、安装maven等、报错Process terminated
  6. 对称机密算法与非对称机密算法
  7. “智囊”机器人:让我为你解答工作中的任何问题!
  8. 14 事务控制和锁定语句
  9. 【vue】---动态路由传值
  10. openjudge-1664 放苹果
  11. 如何在开发时部署和运行前后端分离的JavaWeb项目
  12. XILINX 7系列FPGA与SOC产品选型指南
  13. 如何修改论文,能够避开查重?
  14. TestBench 基本写法与框架
  15. 【SpringBoot 】 组件管理 ,java工程师面试突击中华石杉
  16. 虚拟机突然没网了,虚拟机突然鼠标失灵
  17. 终止正在运行的ORACLE作业
  18. 【拖拽】拖动原理 拖动基本思路
  19. CART与ID3的区别C4.5离散化的过程
  20. 使用 SAP UI5 绘制 Business Rule Control

热门文章

  1. 求 职 信 的 内 容
  2. React - 受控组件与非受控组件(实践妙用-模糊查询)
  3. 免费试用!能快速解决产品性能问题的腾讯工具来了
  4. C# 第六章『交互式图形界面』◆第4节:FileDialog类 、OpenFileDialog类、SaveFileDialog类、示例
  5. MATLAB中split函数使用
  6. 【攻破html系列——第五天】表格标签和列表标签
  7. FBI树Python题解
  8. 我的苹果开发帐号(公司型)成功申请经历——不用传真营业执照、免费获取邓白氏编码
  9. Terrain Splatting
  10. XVNC远程Linux自动锁屏后无法输入密码问题