这是我在这个页面上的第一个问题,所以首先抱歉任何新手错误和我的英语不好.
如果我没有提出如何解决问题的想法,我就不会在这样的页面上询问,所以我希望我能帮助你,因为这是我的最后一次机会.
我使用NHibernate在C#中创建了一个程序,将它连接到我的Oracle数据库(工作正常),现在我被告知创建一个类似的程序,但现在在Windows服务而不是.exe中.
问题是我已完成所有设置以使NHibernate像.exe程序一样工作,如果我调试程序它一切正常,但一旦我安装服务并运行它,停止工作.
我没有在程序中进行任何操作,只是测试NHibernate连接.
例外:
Could not compile the mapping document: Mapping\CSB_Mensaje.hbm.xml System.IO.DirectoryNotFoundException: No se puede encontrar una parte de la ruta de acceso 'C:\Windows\system32\Mapping\CSB_Mensaje.hbm.xml'. en System.IO.__Error.WinIOError(Int32 errorCode,String maybeFullPath) en System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions options,SECURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy,Boolean useLongPath) en System.IO.FileStream..ctor(String path,Int32 bufferSize) en System.Xml.XmlDownloadManager.GetStream(Uri uri,ICredentials credentials,IWebProxy proxy,RequestCachePolicy cachePolicy) en System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri,String role,Type ofObjectToReturn) en System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) en System.Threading.CompressedStack.runTryCode(Object userData) en System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code,CleanupCode backoutCode,Object userData) en System.Threading.CompressedStack.Run(CompressedStack compressedStack,ContextCallback callback,Object state) en System.Xml.XmlTextReaderImpl.OpenUrl() en System.Xml.XmlTextReaderImpl.Read() en System.Xml.XmlTextReader.Read() en System.Xml.XmlCharCheckingReader.Read() en System.Xml.XsdValidatingReader.Read() en System.Xml.XmlLoader.Load(XmlDocument doc,XmlReader reader,Boolean preserveWhitespace) en System.Xml.XmlDocument.Load(XmlReader reader) en NHibernate.Cfg.Configuration.LoadMappingDocument(XmlReader hbmReader,String name)
西班牙语的例外部分,说它无法找到访问路径的一部分.
尝试执行此代码时抛出此异常:
private static void Init(String BBDD) { Configuration config = new Configuration(); config.Configure().SessionFactoryName(BBDD); config.AddFile("Mapping\\CSB_Mensaje.hbm.xml"); config.AddFile("Mapping\\CSB_Periodicidad.hbm.xml"); config.AddFile("Mapping\\CSB_Plantilla.hbm.xml"); config.AddFile("Mapping\\CSB_Subscripciones.hbm.xml"); config.AddFile("Mapping\\CSB_Usuario.hbm.xml"); config.AddFile("Mapping\\CSB_Login.hbm.xml"); config.AddFile("Mapping\\CSB_Configuration.hbm.xml"); _SessionFactory = config.BuildSessionFactory(); }
这是我的hibernate.cfg.xml文件:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory name="Oracle"> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider </property> <property name="dialect"> NHibernate.Dialect.Oracle10gDialect </property> <property name="connection.driver_class"> NHibernate.Driver.OracleClientDriver </property> <property name="connection.connection_string"> User Id=CSB; Password=Hound2012; Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.30)(PORT = 1521)))(CONNECT_DATA = (SID = HL))); </property> <property name="show_sql"> true </property> </session-factory> </hibernate-configuration>
再次,这是我第一次在这里问一些事情,所以我很抱歉任何错误.任何帮助都会大大减少.
问候,
豪尔
解决方法
此行的异常消息表明问题:
System.IO.DirectoryNotFoundException: No se puede encontrar una parte de la ruta de acceso 'C:\Windows\system32\Mapping\CSB_Mensaje.hbm.xml'.
我认为问题是你在这里使用相对路径:
config.AddFile("Mapping\\CSB_Mensaje.hbm.xml");
尝试指定映射文件的实际路径.
或者,将映射文件标记为嵌入式资源,让NHibernate在程序集中找到它们,而不是单独告诉每个映射文件的配置(参见The NHibernate Wiki).