我制作了一个基于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)
问题很明显:代码或配置出了什么问题?我确信密码输入正确,我已经复制了连接字符串的其余部分并替换了密码占位符。我已经设置了防火墙规则,没有防火墙规则你不能使用https://yourdbhost.database.windows.net/
我一直在寻找这个问题的答案几个小时,上面的问题评论使我从Azure管理门户提供的连接字符串中删除了方括号。
连接成功,没有方括号。我的连接字符串现在是(用真实的细节替换粗体部分):
Server=tcp: Server .database.windows.net,1433;Database=MYDB;User ID=USER@SERVER;Password= Password ;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
信不信由你,这个连接字符串通过对FNH代码的轻微修改(只有在改变连接字符串之后它才开始工作)一起工作
Data Source=xxxxx.database.windows.net;Initial Catalog=MyDb;Persist Security Info=True;User ID=zshop;Password=xxxxxxx
代替使用Database
,我必须使用Initial Catalog
和Persist Security Info
。数据库名称
由于错误报告登录失败,我认为罪魁祸首是Persist Security Info
。
现在我有一个问题要在另一个问题中讨论