-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: config: Problem when porting VS.NET2003 -> VS.NET2005
PostPosted: Thu Jul 20, 2006 5:08 pm 
Newbie

Joined: Fri Feb 24, 2006 7:07 am
Posts: 10
Dear forum users,

i have an (for me) unresolvable problem with my application when trying to bring it up and running while porting from VS.NET2003 to VS.NET2005.

With VS.NET2003 everything is working fine - i have to say, i'm new to NHibernate but i got NHibernate up and running within 20 minutes on the old VS.NET2003 (i tried the Quickstart guide on this webpage) and my MSSQL database.

Now, VS.NET2005 arrived and nothing works - it seems there are some problems with the config.

I tried to copy the config from the old VS.NET2003 project, but now i have several different exceptions beeing thrown, when trying to build the sessionFactory. I have checked the PDF-quickstart guide ("NHibernate & IIS - playin with cats"), i have viewed the articles at theserverside.net, i read the tutorials codeproject.com, but i can't find the info to have it working :-(

The config i tried is:
Code:
  <hibernateSettings>
    <session-factory>
      <add key="dialect"
           value="NHibernate.Dialect.MsSql2000Dialect"
             />

      <add key="connection.provider"
           value="NHibernate.Connection.DriverConnectionProvider"
             />

      <add key="connection.connection_string"
           value="Server=XXXX;initial catalog=XXXX;uid=XXXX;pwd=XXXX"
             />

      <mapping assembly="SITApp" />
    </session-factory>
  </hibernateSettings>


the funny exception i recieve is:
Quote:
{"problem parsing configuration : System.IO.FileNotFoundException: Could not find file 'c:\\inetpub\\wwwroot\\sitapp\\bin\\hibernate.cfg.xml'.\r\nFile name: 'c:\\inetpub\\wwwroot\\sitapp\\bin\\hibernate.cfg.xml'\r\n at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at 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)\r\n at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)\r\n at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)\r\n at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)\r\n at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)\r\n at System.Threading.CompressedStack.runTryCode(Object userData)\r\n at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)\r\n at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)\r\n at System.Xml.XmlTextReaderImpl.OpenUrl()\r\n at System.Xml.XmlTextReaderImpl.Read()\r\n at System.Xml.XmlTextReader.Read()\r\n at System.Xml.XmlValidatingReaderImpl.Read()\r\n at System.Xml.XmlValidatingReader.Read()\r\n at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)\r\n at System.Xml.XmlDocument.Load(XmlReader reader)\r\n at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)"}


i don't understand why it's searching for an hibernate.cfg.xml file when i've placed all that stuff in the web.config file.

then, there was another problem when i tried to have a tag starting like:
Code:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">


then i recieve:
Quote:
"Unrecognized attribute 'xmlns'. Note that attribute names are case-sensitive...."


next, i tried to cut out the "xmlns" tag; after that, i recieved:
Quote:
"Unrecognized element."


another issue is:
in VS.NET2003 i have the option to say buildaction -> "embedded resource" for all the hmb.xml mapping files - this option is unavailable for me in VS.NET2005 - it's not there, really ! I don't know why...

please understand:
everything is working fine with VS.NET2003 - but i'm completely unable to get it up and running on VS.NET2005. As said before, i'm fairly new to NHibernate and database programming - before that i acted in standard application development, tools for games and such stuff... but sorry: i don't understand why this stuff won't work on VS.NET2005.

please help !


*****EDIT******

now, what i tried last was, i copied the _original_ config file from the quickstart guide, which looks like:
Code:
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
    <session-factory>
      <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.connection_string">Server=XXXX;initial catalog=XXXX;uid=XXXX;pwd=XXXX</property>
      <mapping assembly="SITApp" />
    </session-factory>
  </hibernate-configuration>


and everything what i recieve, is, the above already mentioned:
Quote:
{"Unrecognized attribute 'xmlns'. Note that attribute names are case-sensitive. (c:\\inetpub\\wwwroot\\sitapp\\web.config line 23)"}


HELL, please help me !
are the quickstart guide examples VS.NET2003 specific ?
i don't understand why it says: "xmlns unrecognized" if i can see that the build-in XML editor is proposing the tag "xmlns" when i start typing - all that stuff worked *perfectly* with the old VS.NET2003 application....


****EDIT NR.2****
i tried both NHibernate versions:
1.0.2 and the latest alpha.

no difference - i get the same error...


****EDIT NR.3****
for some reason, i get different exceptions when switching the name of the hibernate-config block, from:
Code:
  <hibernate-configuration>

to (example):
Code:
  <hibernate>

in the first case, it says ""Unrecognized element."; in the second case it says the above mentioned exception with the looonnnggg text ("unable to parse config...").
SORRY, i don't understand why it throws different exceptions depending on THE NAME i have chosen for the name of the config block ??????


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 3:49 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Please post the <configSections> part of your web.config as well.

Right now, it just can't find your config section so it's looking for the cfg.xml file

The usage should be either:

Code:
<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
   
  <nhibernate>
    <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
    <add key="hibernate.show_sql" value="false" />
    <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
    <add key="hibernate.connection.connection_string" value="Server=(local);Trusted_Connection=true;initial catalog=TIF;" />
      <add key="hibernate.connection.isolation" value="ReadCommitted" />
  </nhibernate>
   
</configuration>



or

Code:

<configuration>
   <configSections>
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
      <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
   </configSections>

   <hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
      <session-factory>
         <property name="hibernate.dialect">NHibernate.Dialect.MsSql2000Dialect</property>
         <property name="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
         <property name="hibernate.connection.connection_string">Server=(local);Trusted_Connection=true;initial catalog=mobyProject;</property>
         <property name="hibernate.show_sql">true</property>
         <property name="hibernate.connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
         <property name="hibernate.connection.isolation">ReadCommitted</property>
         <property name="hibernate.use_proxy_validator">True</property>

         <mapping assembly="mobyProject" />
      </session-factory>
   </hibernate-configuration>
</configuration>



I use the second way and then configure like this:

new Configuration().Configure().BuildSessionFactory();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 8:47 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
I have another suggestion I just thought of... If this is a web app, then you might want to install the patch for VS2005 to give it Web Application Project support:

http://msdn.microsoft.com/asp.net/refer ... fault.aspx

Then re-upgrade your project from 2003 to 2005. I think you'll be much happier with the transition.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 23, 2006 3:38 pm 
Newbie

Joined: Fri Feb 24, 2006 7:07 am
Posts: 10
hi benhyrman.

thank you for your reply.

here is the missing part of the web.config file (even if i haven't posted it, doesn't mean i've forgotten it :) )
Code:
   <configSections>
      <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
   </configSections>


just right now i'm going to try the update/patches you mentioned; but i'm wondering: why do i have to install some updates to have the same functionality !? surely, i'm not dumb - but i can't understand it ???

you said:
Quote:
I use the second way and then configure like this:

new Configuration().Configure().BuildSessionFactory();

to be honestly: i don't know where is there some difference between the first and the second part of the way to configure.

in my old project, everything looked like the above posted sections.
in the new project i get different errors each time i try somehting.

i can tell you somethign: this shit is now taking more than 3 weeks !

i've found a webproject of vs.net2005 outside there, its from a private blog; this guy just build an additional assembly, with all the stuff inside it - i tried this: when i try it the way like this person did it, i just recive "dialect not set"-exception, although i've included the hibernate.cfg.xml in both, the addon-assembly itself and the mainproject.

really, i swear you: i've done bigger projects like this one, but i can't believe its so frustrating to get nhibernate up and running on VS.NET2005.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 23, 2006 3:47 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
If you use the "nhibernate" section, then the config file must contain the <nhibernate> element and its contents should be <add key="hibernate.some_key" value="some_value" />. Note that it's <nhibernate> and that it doesn't contain the <session-factory> element. I suspect that this is your problem.

If this doesn't help, please post all the data about your last attempt - i.e. the entire configuration file here, the code you are using to configure and create the session factory and the exact error message you are getting from NHibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 5:39 am 
Newbie

Joined: Fri Feb 24, 2006 7:07 am
Posts: 10
hi sergey,

thank you for the information.

i noticed the missing "n" at the beginning of the tag, yes - this was because i copied these part out of the VS2003 project, where i have it written without the "n" (this was renamed by me in the new web.config for the VS2005 project).

regarding the sesseionfactory passage:
Code:
   <hibernate>
      <add
         key="hibernate.connection.provider"
         value="NHibernate.Connection.DriverConnectionProvider"
      />
      <add
         key="hibernate.dialect"
         value="NHibernate.Dialect.MsSql2000Dialect"
      />
      <add
         key="hibernate.connection.driver_class"
         value="NHibernate.Driver.SqlClientDriver"
      />
      <add
         key="hibernate.connection.connection_string"
         value="Server=SQLSRV;initial catalog=EVDB;uid=dbuser;pwd=XXXX
      />
   </hibernate>

this is the original part of the app.config of VS2003 project; as you can see, i have no session-factory part; and this config is working for the VS2003 project. i don't understand why i need to have a "sessionfactory" part in VS2005 projects, when it works without on VS2003 ?

the problem regarding the config seems to me was as following:
for some reason it seems to me it's a definite must (in VS2005) to place the hibernate configuration in a seperate/extern xml file, when trying to integrate it into the web.config it won't work...

currently i have the following situation with the VS2005 (web)project:
it compiles and runs without exception during initialization.
it seems, everything is fine now - but i still have one problem:
all Session.List()-calls are returing an empty list with no items included, this is because i haven't embedded-resource-compiled the hbm.xml files for the tables - as said above, on VS2005 ASP.NET websites its no more possible to select this build action.
Then, i thought it will be okay if i do a simple cfg.AddClass(...) - but this call returns with an exception, saying it can't find the file XYZ.hbm.xml - i placed this files in two different locations (root of project & bin-folder), but it tells me the error all the time - so, please tell me, where to i have to place the XYZ.hbm.xml files ?

benhyrman,
thank you for the info with this patch. it seems some kind of inconvenient to me to install two patches before using the stuff :-/ so i will do this if i can't find any other solution; but as said above, it looks like i'm reachin the point where it will work.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 8:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
First, please read carefully what I and others wrote about nhibernate/hibernate-configuration elements and what goes into which one, it looks to me that you are still mixing things up. But I admit it is a confusing area.

You can use Configuration.AddFile or AddDirectory to add mapping files which are not embedded resources.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 10:02 am 
Newbie

Joined: Fri Feb 24, 2006 7:07 am
Posts: 10
Hi.

yes, i'm aware of that the block/tag names of the config-passage must match the name in the <configSection>.

Finally, i got it up and running, just 2 minutes ago:

- i built an extra DLL/assembly for the dataaccess, as mentioned in other forumposts.

- then there was the first problem: i called the function AddAssembly(...) on the new DLL/assembly; this is not necessary, and it told me all the time "dialect not set"; then i found out - by trying&erroring - that i don't need to call AddAssembly(...) when i have placed the stuff in an extra assembly - i don't know why and i don't understand it, but it want's it that way

- the next proble was an exception with text like "...get_id needs to be virtual...":
for some reason i need to have the functions in the .cs-class declared virtually (even if use no derivation/inheritance)

- no i've placed the config in an extra xml file; but i will try, putting it back into the web.config (by the way, is there and advance when placing the config in a seperate xml in comparison to the web.config-way ?)

all that stuff is really confusing :-| but luckily it works, now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.