0

我制作了一个基于 Fluent NHibernate 的简单 SQL 生成器 XAML 应用程序,它允许我生成 DDL 以在数据库上运行。使用本地 MySQL 设置它可以正常工作。

我现在想在 SQL Azure 上运行它。

  • 我创建了一个网站,将在管理门户上托管 NH 应用程序。查看!
  • 我已经创建了 NH 应用程序使用的数据库。查看!
  • 我已设置防火墙规则以允许我的 IP 地址连接到 SQL Azure。查看!
  • 我尝试连接到 Azure 的官方数据库管理门户并使用我的凭据登录。查看!
  • 我尝试使用正确的连接字符串(仔细检查密码)运行 NHibernate 模式生成器,但出现错误。繁荣!

错误(匿名)如下

---------------------------

---------------------------
Cannot open database "[MyDb]" requested by the login. The login failed.

Login failed for user 'mydblogin'.

This session has been assigned a tracing ID of '{{guid}}'.  Provide this tracing ID to customer support when you need assistance.
---------------------------
OK   
---------------------------

代码:

PersistenceConfigurer persistenceConfigurer = MsSqlConfiguration.MsSql2008
    .Dialect<MsSqlAzure2008Dialect>()
    .Driver<SqlClientDriver>()
    .FormatSql()
    .ShowSql()
    .ConnectionString(connectionString);

FluentConfiguration fc = Fluently.Configure()
    .Database(persistenceConfigurer)
    .ExposeConfiguration(
        cfg => cfg.SetProperty("hbm2ddl.keywords", "auto-quote")
                    .SetProperty("hbm2ddl.auto", "none"))
    .Mappings(
    m => m.FluentMappings.AddFromAssemblyOf<NHibernateFactory>()
    .Conventions.AddFromAssemblyOf<NHibernateFactory>());
Configuration ret = fc.BuildConfiguration();
SchemaMetadataUpdater.QuoteTableAndColumns(ret);

连接字符串(混淆)

Server=tcp:dbhost.database.windows.net,1433;Database=[MyDb];User ID=login@dbhost;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;

例外是System.Data.SqlClient.SqlException (0x80131904)

堆栈跟踪

   in System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   in System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   in System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   in System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   in System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   in System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   in System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   in System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   in System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions)
   in System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   in System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   in System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions)
   in System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions)
   in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   in System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   in System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   in System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   in System.Data.SqlClient.SqlConnection.Open()
   in NHibernate.Connection.DriverConnectionProvider.GetConnection()
   in NHibernate.Tool.hbm2ddl.ManagedProviderConnectionHelper.Prepare()
   in NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
   in NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(IDictionary`2 cfgProperties)
   in NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.QuoteTableAndColumns(Configuration configuration)
   in HbmSchemaExporter.NHibernateManager.BuildNHConfig(String connectionString, DbType dbType, Dialect& requiredDialect)
   in HbmSchemaExporter.NHibernateManager.GenerateSql(MainWindowViewModel viewModel)
   in HbmSchemaExporter.MainWindow.btnGenerateSql_Click(Object sender, RoutedEventArgs e)

问题很明显:代码或配置有什么问题?我确定密码输入正确,我已经复制了连接字符串的其余部分并替换了密码占位符。我已经设置了防火墙规则和没有防火墙规则的 AFAIK,你不能使用https://yourdbhost.database.windows.net/

4

2 回答 2

2

几个小时以来,我一直在寻找这个确切问题的答案,上面的问题评论使我从 Azure 管理门户提供的连接字符串中删除了方括号。

连接成功,没有方括号。我的连接字符串现在是(用真实细节替换粗体部分):

Server=tcp: SERVER .database.windows.net,1433;Database= MYDB ;User ID= USER@SERVER ;Password= PASSWORD ;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;

于 2013-03-31T01:39:51.030 回答
0

信不信由你,这个连接字符串与对 FNH 代码的轻微修改一起工作(只有在更改 conn 字符串后它才开始工作)

Data Source=xxxxx.database.windows.net;Initial Catalog=MyDb;Persist Security Info=True;User ID=zshop;Password=xxxxxxx

而不是使用Database我不得不使用Initial Catalogand Persist Security Info。数据库名称不带括号

由于错误报告登录失败,我认为罪魁祸首是Persist Security Info.

现在我有另一个问题要在另一个问题中讨论

于 2013-03-23T13:23:12.567 回答