0

私は NHibernate を勉強し、ビデオ コースからアプリケーションの作成を繰り返してみ
ました。データベース、モデル、XML ファイルを作成し、このコードを書きました。

using System;
using System.Reflection;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;

namespace NHibernateDemo
{
internal class Program
{
    static void Main(string[] args)
    {
        var cfg = new Configuration();
        cfg.DataBaseIntegration(x =>
            {
                x.ConnectionString = "Server=localhost; Database=NHibernateDemo; Integrated Security = SSPI";
                x.Driver<SqlClientDriver>();
                x.Dialect<MsSql2008Dialect>();
            });
        cfg.AddAssembly(Assembly.GetExecutingAssembly());
        var sessionFactory = cfg.BuildSessionFactory();
        using (var session = sessionFactory.OpenSession())
        using (var tx = session.BeginTransaction())
        {
            var customers = session.CreateCriteria<Customer>()
                                   .List<Customer>();
            foreach (var customer in customers)
            {
                Console.WriteLine("{0} {1}", customer.FirstName, customer.LastName);
            }
            tx.Commit();
            Console.WriteLine("Enter any key to exit...");
            Console.ReadKey();
        }
    }
}
}

しかし、デバッグしようとすると、SqlExeption was unhandled が発生しました

ここに画像の説明を入力

コードにログインとパスワードを追加する必要があると思いますが、その方法を説明してもらえますか?

4

1 に答える 1

2

統合されたセキュリティを使用しています。コードを実行しているユーザーはアクセスできる必要があります。

Server=localhost; Database=NHibernateDemo; Integrated Security = SSPI

SQL アカウントを使用するように接続文字列を変更するか、ユーザーにデータベースへのアクセスを許可することができます。

接続文字列の構成: connectionstrings

于 2013-07-24T08:10:26.450 に答える