我在winform应用程序中使用JRO在Windows Server 2008 R2(64位)服务器上压缩访问数据库时遇到问题。我按照以下步骤操作:
开发PC的配置:
操作系统:Windows XP Professional版本:2002(SP3)32Bit
MSOffice 2003已安装:是
Visual Studio:2010 Premium
.Net框架:4.0.30319
创建了两个带有以下代码的winform App:
应用程序1:用于压缩Access 2007 DB
目标平台设置为x86并添加了Microsoft Jet和Replication Objects 2.6库的参考
配置文件:
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup>
<appSettings>
<add key="SourceDB" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Test\Test2007.accdb;Jet OLEDB:Engine Type=5"/>
<add key="DestDB" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Test\Test2007BK.accdb;Jet OLEDB:Engine Type=5"/>
<add key="AppDB" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Test\Test2007.accdb;" />
</appSettings>
</configuration>
代码:
string SrcDBName = ConfigurationManager.AppSettings["SourceDB"];
string DestDBName = ConfigurationManager.AppSettings["DestDB"];
int ReturnCode = 0;
JRO.JetEngine objJRO = null;
try
{
MessageBox.Show("Start Compact");
objJRO = new JRO.JetEngine();
objJRO.CompactDatabase(SrcDBName, DestDBName);
MessageBox.Show("End Compact");
}
catch (Exception ex)
{
MessageBox.Show("Error in Compact");
ReturnCode = -1;
StackTrace STrace = new StackTrace(ex, true);
StackFrame StkFrame = STrace.GetFrame(STrace.FrameCount - 1);
string Disp_Msg = "Message:\t" + ex.Message + Environment.NewLine;
Disp_Msg += "Error Date:\t" + DateTime.Now.ToString("dddd, MMM d yyyy HH:mm:ss");
//MessageBox.Show(Disp_Msg, "Compact Utility", MessageBoxButtons.OK, MessageBoxIcon.Error);
File.AppendAllText(Path.GetDirectoryName(Application.ExecutablePath) + @"\CompactErr.txt", Disp_Msg + Environment.NewLine + "Stack Trace:\t" + ex.StackTrace + Environment.NewLine + Environment.NewLine);
}
finally
{
Marshal.ReleaseComObject(objJRO);
objJRO = null;
}
应用程序2:用于测试与Access 2007的连接
private void Form1_Load(object sender, EventArgs e)
{
try
{
//Connection Test
MessageBox.Show("Start DBConn");
TestConn();
MessageBox.Show("End DBConn");
}
catch (Exception ex)
{
MessageBox.Show("Error in Conn Opening");
string Disp_Msg = "Message:\t" + ex.Message + Environment.NewLine;
Disp_Msg += "Error Date:\t" + DateTime.Now.ToString("dddd, MMM d yyyy HH:mm:ss");
File.AppendAllText(Path.GetDirectoryName(Application.ExecutablePath) + @"\CompactErr.txt", Disp_Msg + Environment.NewLine + "Stack Trace:\t" + ex.StackTrace + Environment.NewLine + Environment.NewLine);
}
}
public void TestConn()
{
string strConnectionString = ConfigurationManager.AppSettings["AppDB"];
DbConnection objConnection;
DbProviderFactory objFactory = OleDbFactory.Instance;
objConnection = objFactory.CreateConnection();
objConnection.ConnectionString = strConnectionString;
objConnection.Open();
objConnection.Close();
}
现在,在Win2008服务器上部署了2个以上的exe:
服务器详细信息:
Windows Server 2008 R2(SP1) - 64位
没有MSOffice
没有Visual Studio
已安装:Microsoft Office Access数据库引擎2010
案例1:安装Access DB Engine 2010(64位)时:
链接:http://www.microsoft.com/download/en/details.aspx?id=13255
消息:未注册的班级
堆栈跟踪:在JRO.IJetEngine.CompactDatabase(String SourceConnection,String Destconnection)
在CompactUtility.Program.Main(String [] args)
案例2:安装Access DB Engine 2007时:
链接:http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23734
任何建议/帮助都将非常感谢您解决在Windows Server 2008(64位)服务器上工作的问题。
另请参阅以下链接,但没有帮助:
Microsoft.ACE.OLEDB.12.0 provider is not registered
谢谢, 沙
答案 0 :(得分:0)
我知道,这是一个古老的问题,但This link确实帮助我解决了第二个问题。 如果我没记错的话,问题源于引擎的64位问题。 Adding the Component进入Visual Studio应该可以解决此问题。