简体   繁体   English

ADODB从Excel 2013连接到.mdb文件

[英]ADODB connection to .mdb file from excel 2013

I hope someone can help. 我希望有人能帮帮忙。 I've developed an excel package that updates a .mdb access database through the connection string "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\" The database is shared. 我已经开发了一个Excel程序包,该程序包通过连接字符串“ Provider = Microsoft.Jet.OLEDB.4.0; Data Source = \\”更新了.mdb访问数据库。数据库是共享的。 I have a Mitel telephony system that checks the database every 10 seconds or so to check for a new entry. 我有一个Mitel电话系统,该系统每10秒钟左右检查一次数据库,以检查是否有新条目。 The database is updated with 数据库更新为

Dim q As New ADODB.Command
Dim cn As New ADODB.Connection
Dim SQL As String
SQL = "INSERT INTO tbl1LinkAuths (DateTimeAdded, DateEntered, AddedBy, REG,                                    OrderNo,AccountNumber, CentreNumber, EmailAddress, Callback, "
SQL = SQL & "MakeText, "...............

cn.Open cnDB
q.ActiveConnection = cn
q.CommandText = SQL
'Excecute the above SQL to insert the new job record
q.Execute


Set rs = Nothing
Set cn = Nothing

Dim db As Access.Application
Set db = New Access.Application
db.Application.Visible = False
db.OpenCurrentDatabase "\\kffcis02\VWM Share\TelephonyDB.mdb", False
db.CloseCurrentDatabase

The INSERT statement updates the database fine, but I find I have to open and close the database to get it to update in time. INSERT语句可以很好地更新数据库,但是我发现必须打开和关闭数据库才能及时更新数据库。

This package is used heavily by around 5 people at a time, making about 2 entries per minute. 一次大约有5个人大量使用此软件包,每分钟输入2个条目。

It comes up with the error "file already in use", especially when using excel 2013, a lot of the time. 它会出现错误“文件已在使用中”,尤其是在很多时候使用excel 2013时。 I think this is because I have to open/close the database every time I update. 我认为这是因为每次更新时都必须打开/关闭数据库。

Does anybody know of a different way I can get the database to update quicker? 有人知道我可以更快地更新数据库的另一种方式吗? I've got the actual database setting to update ADODB every second and the database is shared. 我已经有了实际的数据库设置来每秒更新ADODB并共享数据库。

I'm now desperate, as this package has went live. 我现在很绝望,因为这个程序包已经上线了。 I didn't have any problems during testing because there wasn't as many people using it and none of them were on office 2013. 在测试期间,我没有任何问题,因为使用它的人不多,而且没有人在Office 2013中使用。

Wrong driver: Assuming a reference to activex data objects... 驱动程序错误:假设对ActiveX数据对象的引用...

dim conn as  adodb.connection    'module level variable
const DBNAME = "your name here"
const DBLOC = "Your dir here"

 Sub UpdateDb()

dim sql as string
openconnectionroutine
sql = "INSERT INTO tbl1LinkAuths (DateTimeAdded, DateEntered, AddedBy, "
'etc
'if you want to check it worked : otherwise ditch numrecs
 dim numrecs as long
conn.execute sql, numrecs
msgbox "You added " & numrecs & " records",vbokonly,"Done"

end sub

sub Openconnectionroutine() 
if conn is nothing then set conn = new adodb.connection
if conn.connectionstring = "" then
    conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" & _
                 "Dbq=" & DBNAME & ";" & _
                 "DefaultDir=" & DBLOC & ";" & _
                 "Uid=Admin;Pwd=;"
 end if
 if conn.state = adstateopen then
 else                
   conn.Open
 end if

End sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM