当前位置:编程学习 > C#/ASP.NET >>

64位机器windows服务问题咨询

我编译的一个windows服务,编译选择的平台是 Any CPU,主要功能是定时读取数据库进行操作

在32位机器上安装成功后,可以定时读取数据库操作,但是在64位机器上安装也可以安装,就是安装后服务里面的内容好像不执行,没有任何效果,不知道是什么问题  大致源码如入:


              
try
            {
                timer1.Enabled = false;
                OleDbConnection odbcon = Common.CresteOledbcon();
                odbcon.Open();
                SqlConnection sqlcon = Common.CresteSqlcon();
                sqlcon.Open();
                SqlCommand sqlcmd = new SqlCommand();
                sqlcmd.Parameters.Add(new SqlParameter("@ffile", SqlDbType.Image));
                sqlcmd.Connection = sqlcon;
                sqlcmd.CommandTimeout = 0;
                OleDbCommand odbcmd = new OleDbCommand("select * from TmCallRecTable where 状态<>'未接'", odbcon);
                odbcmd.CommandTimeout = 0;
                OleDbDataReader odr = odbcmd.ExecuteReader();
                while (odr.Read())
                {
                    if (odr["录音文件"].ToString().Length > 0 && File.Exists(odr["录音文件"].ToString()))
                    {
                        try
                        {
                            FileStream stream = new FileStream(odr["录音文件"].ToString(), FileMode.Open);
                            byte[] blob = new byte[stream.Length];
                            stream.Read(blob, 0, (int)stream.Length);
                            stream.Close();
                            sqlcmd.Parameters["@ffile"].Value = blob;
                            sqlcmd.CommandText = "set nocount on insert into t_dail(fdate,flenth,fout,fnumber,fipaddress,fserialno,ffile) values('" + string.Format("{0:yyyy-MM-dd HH:mm:ss}", odr["开始时间"]) + "','" + odr["通话时间"] + "','" + odr["类型"] + "','" + odr["号码"] + "','" + getIPAddress() + "','" + odr["序列号"] + "',@ffile)";
                            sqlcmd.ExecuteNonQuery();
                            DeleteString.Add(odr["ID"].ToString());
                            File.Delete(odr["录音文件"].ToString());
                        }
                        catch
                        {                         
                        }
                    }
                    else
                    {
                        DeleteString.Add(odr["ID"].ToString());
                    }
                }
                odr.Close();
                try
                {
                    foreach (string DeleteID in DeleteString)
                    {
                        odbcmd.CommandText = "delete from TmCallRecTable where ID=" + DeleteID + "";
                        odbcmd.ExecuteNonQuery();
                    }
                }
                catch
                {
                }
                finally
                {
                    DeleteString.Clear();
                }
                odbcon.Close();
                sqlcon.Close();
            }
            catch
            {
            }
            finally
            {
                timer1.Enabled = true;
            }
windows服务  64位机器 --------------------编程问答-------------------- 求高人解答啊,困扰了一周了 --------------------编程问答-------------------- 用x64编译试试 --------------------编程问答-------------------- 检查下权限、文件路径。调试下。 --------------------编程问答-------------------- 读的Access? 64位下没oledb驱动 编译成x86平台试试
  
*****************************************************************************
http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- 我选择x86编译就回报如下错误,选any cpu就不会拨错

有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
System.BadImageFormatException: 未能加载文件或程序集“file:///C:\Program Files\电话录音系统\Manager\KDDail.exe”或它的某一个依赖项。试图加载格式不正确的程序。
文件名:“file:///C:\Program Files\电话录音系统\Manager\KDDail.exe”
   在 System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   在 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   在 System.Reflection.Assembly.LoadFrom(String assemblyFile)
   在 System.Configuration.Install.AssemblyInstaller.set_Path(String value)
   在 ServiceSetup.Form1.Form1_Load(Object sender, EventArgs e)
   在 System.Windows.Forms.Form.OnLoad(EventArgs e)
   在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   在 System.Windows.Forms.Control.CreateControl()
   在 System.Windows.Forms.Control.WmShowWindow(Message& m)
   在 System.Windows.Forms.Control.WndProc(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

警告: 程序集绑定日志记录被关闭。
要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)设置为 1。
注意: 会有一些与程序集绑定失败日志记录关联的性能损失。
要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。



************** 已加载的程序集 **************
mscorlib
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
ServiceSetup
    程序集版本: 1.0.0.0
    Win32 版本: 
    基本代码: file:///C:/Program%20Files/电话录音系统/Manager/ServiceSetup.exe
----------------------------------------
System.Windows.Forms
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.ServiceProcess
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.ServiceProcess/2.0.0.0__b03f5f7f11d50a3a/System.ServiceProcess.dll
----------------------------------------
System.Configuration.Install
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration.Install/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.Install.dll
----------------------------------------
System.Windows.Forms.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------

************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。

例如: 

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。


引用 4 楼 feiyun0112 的回复:
读的Access? 64位下没oledb驱动 编译成x86平台试试
  
*****************************************************************************
http://feiyun0112.cnblogs.com/
--------------------编程问答-------------------- 而且,我建立了新的工程做成非服务的运行的OK的,也不存在oledb驱动问题,真是奇怪了
引用 4 楼 feiyun0112 的回复:
读的Access? 64位下没oledb驱动 编译成x86平台试试
  
*****************************************************************************
http://feiyun0112.cnblogs.com/
--------------------编程问答--------------------
引用 4 楼 feiyun0112 的回复:
读的Access? 64位下没oledb驱动 编译成x86平台试试
  
*****************************************************************************
http://feiyun0112.cnblogs.com/


+1
oledb驱动问题,如果程序中使用了第三方或者某些Win API,在DllImport时类型封装不准确,也会出现兼容性问题 --------------------编程问答-------------------- System.BadImageFormatException: 未能加载文件或程序集“file:///C:\Program Files\电话录音系统\Manager\KDDail.exe”或它的某一个依赖项。试图加载格式不正确的程序。

就是第三方的程序集与运行平台不匹配导致的,要实现兼容,你得找类库提供者
或者想办法编译成x86程序 --------------------编程问答-------------------- 你自己的机器是x64的,那dll也是x64的,所以你选Any CPU和x64编译都能过
你得找他们要一个x86版的
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,