Hey,
I have this project where a user must log in into his account and then
they can create contacts in their database.
There is 1 global connectionstring > for checking if the user is
valid.
When the user is valid, it has its own connectionstring.
Example:
User ID=sa;Password=test;Data Source=db_general;Initial
Catalog=database > general connectionstring
User ID=sa;Password=test;Data Source=db_user1;Initial Catalog=database
> connectionstring for user 1
User ID=sa;Password=test;Data Source=db_user2;Initial Catalog=database
> connectionstring for user 2
For now I use only 1 connectionstring. Like this:
In the hibernate.cfg;xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
<property name="connection.connection_string">User
ID=sa;Password=test;Data Source=db_general;Initial Catalog=database</
property>
<property name="adonet.batch_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</
property>
<property name="command_timeout">60</property>
<property
name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
NHibernate.ByteCode.LinFu</property>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
</session-factory>
</hibernate-configuration>
Getting data, for example:
CtInfo.cs > contact
public static CtInfo GetById(int? pId)
{
using (ISession session = SessionHelper.OpenSession())
{
return session.Get<CtInfo>(pId);
}
}
SessionHelper.cs:
private static ISessionFactory _sessionFactory;
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
Configuration config = new
Configuration().Configure();
config.AddAssembly(typeof(CtInfo).Assembly);
_sessionFactory = config.BuildSessionFactory();
if (_sessionFactory == null)
throw new InvalidOperationException("Could not
build SessionFactory");
}
return _sessionFactory;
}
}
public static ISession OpenSession()
{
ISession session = SessionFactory.OpenSession();
if (session == null)
throw new InvalidOperationException("Cannot open
session");
return session;
}
The connectionstring is automatically given to SessionFactory. Do I
need to create a new SessionFactory for each user?? Or is there a
better way?
Like something like this
public static CtInfo GetById(int? pId, string pConnectionString)
{
//give connectionstring to session factory??
Thanks in advance.
CompuFit.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.