我是 C# 和所有 .net 的新手。我正在尝试使用测试控制台应用程序测试我的 Nhibernate 配置。
这是我的测试控制台应用程序
class Program
{
static void Main(string[] args)
{
try
{
NHibernateBase NHB = new NHibernateBase();
NHB.Initialize("NHibernate.GuitarStore");
System.Console.WriteLine("NHibernate.GuitarStore assembly initialized.");
System.Console.ReadLine();
}
catch (Exception ex)
{
string Message = ex.Message;
if (ex.InnerException != null)
{
Message += " - InnerExcepetion: " + ex.InnerException.Message;
}
System.Console.WriteLine();
System.Console.WriteLine("***** ERROR *****");
System.Console.WriteLine(Message);
System.Console.WriteLine();
System.Console.ReadLine();
}
}
}
当我运行上面的程序时,我得到了错误:
***** ERROR *****
Login failed for user 'BUGZILLA\Silon'.
这是我的 app.config 中的连接字符串
connectionString="Data Source=localhost;Initial Catalog=myGuitarStore;Integrated Security=True
我认为这与连接字符串的集成安全部分有关。
问题是我不理解连接字符串中的属性(及其含义),而且我似乎找不到任何可以简单地解释它们的文章。
----以防万一您需要它来理解问题,这里是 NHibernateBase 类
public class NHibernateBase
{
private static Configuration Configuration { get; set; }
protected static ISessionFactory SessionFactory { get; set; }
private static ISession session = null;
private static IStatelessSession statelessSession = null;
public static Configuration ConfigureNHibernate(string assembly)
{
Configuration = new Configuration();
Configuration.AddAssembly(assembly);
return Configuration;
}
public void Initialize(string assembly)
{
Configuration = ConfigureNHibernate(assembly);
SessionFactory = Configuration.BuildSessionFactory();
}
public static ISession Session
{
get
{
if (session == null)
{
session = SessionFactory.OpenSession();
}
return session;
}
}
public static IStatelessSession StatelessSession
{
get
{
if (statelessSession == null)
{
statelessSession = SessionFactory.OpenStatelessSession();
}
return statelessSession;
}
}
public IList<T> ExecuteICriteria<T>()
{
using (ITransaction transaction = Session.BeginTransaction())
{
try
{
IList<T> result = Session.CreateCriteria(typeof(T)).List<T>();
transaction.Commit();
return result;
}
catch (Exception ex)
{
transaction.Rollback();
throw ex;
}
}
}