怎样忽略的MS Access启动使用OLE什么时候? [英] How Do I Bypass MS Access Startup When Using OLE?

查看:188
本文介绍了怎样忽略的MS Access启动使用OLE什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做使用C#和OLE访问数据库中的XML自动出口。一切都可以正常使用,只是显示启动窗体,并不会关闭,无需用户干预。

下面是我在做什么,到目前为止:

  objAccess =的CreateObject(Access.Application);
objAccess.OpenCurrentDatabase(C:\\\\ MYDB.MDB,真正的); // TRUE =以独占方式打开
objAccess.ExportXML(0,TestTable的,C:\\\\的test.xml);
objAccess.CloseCurrentDatabase();
objAccess.Quit();


解决方案

据我所知道的唯一方法是使用/ nostartup开关MSACCESS.EXE

所以,你必须使用shell命令来获取访问对象

我有打开一个数据库,并返回对象(这是VBA code,你将不得不转换为C#)

函数

 专用功能OpenDatabaseWithShell(pDatabaseFullPath作为字符串)作为Access.Application昏暗AccObj作为Access.Application    对错误转到的ErrorHandler    设置OpenDatabaseWithShell =什么    DIM CMD作为字符串    在错误恢复下一页    基本建成全面MSACCESS.EXE路径和追加数据库名称和命令开关
    CMD = SysCmd(acSysCmdAccessDir)及MSACCESS.EXE与& psDatabaseFullPath&安培;
    CMD = CMD&安培; / nostartup /不含    开始与壳牌的MS Access
    壳牌路径名称:= CMD    不要'等待外壳进程来完成。
      ERR = 0
      设置AccObj = GetObject的(pDatabaseFullPath)
    循环while ERR<> 0    对错误转到的ErrorHandler    回归访问对象
    设置OpenDatabaseWithShell = AccObjNormalExit:
    退出功能的ErrorHandler:
    这里的错误记录
    退出功能结束功能

编辑:
下面是一些VB.NET code,做了类似的事情链接。向下滚动到创建完整的示例Visual Basic .NET项目和寻找ShellGetDB功能

I am trying to do an automated xml export from an access database using C# and OLE. Everything is working perfectly except that the startup form is shown and won't close without user intervention.

Here's what I am doing so far:

objAccess = CreateObject("Access.Application");
objAccess.OpenCurrentDatabase("C:\\MYDB.mdb", true); //true = open in exclusive mode
objAccess.ExportXML(0, "TestTable", "c:\\test.xml");
objAccess.CloseCurrentDatabase();
objAccess.Quit();

解决方案

As far as I know the only way is to use the /nostartup switch on msaccess.exe

So you have to use shell command to get the access object

I have a function that opens a database and returns the object (This is VBA code which you will have to convert to C#)

Private Function OpenDatabaseWithShell(pDatabaseFullPath As String) As Access.Application

Dim AccObj As Access.Application

    On Error GoTo ErrorHandler

    Set OpenDatabaseWithShell = Nothing

    Dim cmd As String

    On Error Resume Next

    ' basically build full msaccess.exe path and append database name and command switches
    cmd = SysCmd(acSysCmdAccessDir) & "MSAccess.exe """ & psDatabaseFullPath & """"
    cmd = cmd & " /nostartup /excl"

    'start ms access with shell
    Shell PathName:=cmd

    Do 'Wait for shelled process to finish.
      Err = 0
      Set AccObj = GetObject(pDatabaseFullPath)
    Loop While Err <> 0

    On Error GoTo ErrorHandler

    'return access object
    Set OpenDatabaseWithShell = AccObj

NormalExit:
    Exit Function

ErrorHandler:
    'error logging here
    Exit Function

End Function

EDIT: Here's a link to some VB.NET code that does a similar thing. Scroll down to "Create the Complete Sample Visual Basic .NET Project" and look for the "ShellGetDB" function

这篇关于怎样忽略的MS Access启动使用OLE什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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