我已經做了一個基於Fluent NHibernate的簡單的SQL生成器XAML應用程序,它允許我生成DDL以運行到數據庫。通過本地MySQL設置,它可以正常工作。無法從本地機器連接到SQL Azure
我現在想將它運行到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 [email protected];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/
(可能是一個愚蠢的評論)SQL Azure需要SSL。你是否檢查過你的連接字符串包含Encrypt = True; ? – jbl 2013-03-22 10:45:07
+1,因爲它不是一個愚蠢的評論:),無論如何,我的連接字符串中的加密= True! – 2013-03-22 11:03:10
如果您編輯原始問題以包含連接字符串(當然不包含真正的數據庫憑證),可能會有所幫助。 – 2013-03-22 11:54:48