连接到vb6中的远程MS Access数据库 [英] Connect to a remote MS Access database in vb6

查看:151
本文介绍了连接到vb6中的远程MS Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我想连接到位于远程计算机上的远程MS Access数据库。我想用ip地址(\\xxx.xxx.xxx.xxx \mydb \ acc.mdb)或通过机器名称(如\\mymachine\mydb\acc)来做.mdb)



有谁能指导我,我们如何做到这一点,并帮助我连接到远程数据库所需的字符串?



-

AJ

Hi
I want to connect to a Remote MS Access Database which is located on a remote machine. I was thinking of doing it either with the ip address (\\xxx.xxx.xxx.xxx\mydb\acc.mdb) or through the machine name (like \\mymachine\mydb\acc.mdb)

Can anyone please guide me as how we can do this and help me with the string required to connect to a remote database?

--
AJ

推荐答案

首先,如果您有选择,请不要使用VB6是一个遗留环境。所以如果可能转移到VB.NET。



其次,Access基本上只是一个平面文件,所以你需要的是访问文件本身。您可以使用IP或UNC映射共享,也可以使用不映射的文件。



第三,你没有提到你想要使用的技术。如果你真的需要使用VB6,我认为ADO将是合乎逻辑的选择。以下是使用ADO如何使用ODBC连接到Access数据库的一个教程: http://www.vb6 .us / tutorials / database-access-ado-vb6-tutorial [ ^ ]
First, if you have a choice, don't use VB6 which is a legacy environment. So if possible shift to VB.NET.

Secondly, Access is basically just a flat file so what you need is access to the file itself. You can map the share using both IP or UNC or use the file without mapping.

Thirdly, you didn't mention the technology you want to use. If you are really required to use VB6, I think ADO would be the logical choice. Here's one tutorial how to connect to an Access database with ODBC using ADO: http://www.vb6.us/tutorials/database-access-ado-vb6-tutorial[^]


大家好



我找到了解决这个问题的方法,


您必须将数据库放在共享文件夹中,例如:C:\ SharedFolder \ database.mdb,共享您的SharedFolder。



现在假设您的计算机的IP地址是192.168.1.22然后您可以使用以下方法从VB6访问它: -



Public cn As ADODB.Connection

Public rs As ADODB.Recordset



公共函数DBConnect()



On Error GoTo openErr



'Dim cn As ADODB.Connection

'Dim rs As ADODB.Recordset <无线电通信/>


将MSDatabase调暗为字符串



'MSDatabase = App.Path& \& database.mdb'这是有效的



MSDatabase =\\192.168.1.22 \ SharedFolder \ database.mdb



设置cn =新ADODB.Connection



cn.CursorLocation = adUseClient

cn.Provider = Microsoft.Jet.OLEDB.4.0

cn.Open MSDatabase,Admin

MsgBox数据库连接

退出功能

openErr:

MsgBoxDatabae未连接

结束功能





希望这可以帮助每个面临同样问题的人



Chers !!!



- -

AJ
Hi all

I found a solution for this thing,

You got to put your database in a shared folder e.g: C:\SharedFolder\database.mdb where your "SharedFolder" is shared.

Now supposed the ip address of your computer is 192.168.1.22 then you can access it from VB6 using: -

Public cn As ADODB.Connection
Public rs As ADODB.Recordset

Public Function DBConnect()

On Error GoTo openErr

'Dim cn As ADODB.Connection
'Dim rs As ADODB.Recordset

Dim MSDatabase As String

'MSDatabase = App.Path & "\" & "database.mdb" 'This works

MSDatabase = "\\192.168.1.22\SharedFolder\database.mdb"

Set cn = New ADODB.Connection

cn.CursorLocation = adUseClient
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open MSDatabase, Admin
MsgBox "Database connected"
Exit Function
openErr:
MsgBox "Databae not connected"
End Function


Hope this helps everyone who are facing the same problem

Chers!!!

--
AJ


Dim cn As Object
Dim rst As Object
Dim strConnection As String
Dim strSql As String

Set cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & "path of the file" & "Data.mdb"
strSql = "SELECT * FROM User_Login where User_Id=’username';"
cn.Open strConnection
Set rst = cn.Execute(strSql)

If rst.BOF And rst.EOF Then
MsgBox "No data found"
Exit Sub
Else
uname1 = Trim(rst.Fields(0))
pwd1 = Trim(rst.Fields(1))
End If

rst.Close
Set rst = Nothing
cn.Close
Set cn = Nothing





参考此内容更多细节


这篇关于连接到vb6中的远程MS Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆