0

我已经按照这个[问题](http://stackoverflow.com/questions/13691575/servicestack-ormlite-with-mutliple-database-servers)给出的答案,但我仍然得到一个错误。错误是:

{System.Data.SqlClient.SqlException(0x80131904):无效的对象名称“双重”。在 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔 breakConnection,操作1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 在 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject state&Obj, Boolean dataReady) 在 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() 在 System.Data.SqlClient.SqlDataReader.get_MetaData() 在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 在 System.Data System.Data 中的 .SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔 returnStream,布尔异步,Int32 超时,任务和任务,布尔异步写入)。SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔返回流,字符串方法,TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at ServiceStack.MiniProfiler.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() at ServiceStack.OrmLite.OrmLiteReadExtensions.ExecReader(IDbCommand dbCmd, String sql) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\OrmLiteReadExtensions.cs:line 48 at ServiceStack.OrmLite.OrmLiteReadExtensions.GetScalar[T](IDbCommand dbCmd, String sql, Object[] sqlParams) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\OrmLiteReadExtensions.cs:line 498 at ServiceStack.OrmLite.Oracle.OracleOrmLiteDialectProvider.GetNextValue(IDbCommand dbCmd, String sequence, Object value) at ServiceStack.OrmLite.Oracle.OracleOrmLiteDialectProvider.ToInsertRowStatement(Object objWithProperties, IList1 insertFields, IDbCommand dbCommand) 在 ServiceStack.OrmLite.OrmLiteDialectProviderBase 1.ToInsertRowStatement(Object objWithProperties, IDbCommand command) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\OrmLiteDialectProviderBase.cs:line 439 at ServiceStack.OrmLite.OrmLiteWriteExtensions.Insert[T](IDbCommand dbCmd, T[] objs) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\OrmLiteWriteExtensions.cs:line 394 at ServiceStack.OrmLite.OrmLiteWriteConnectionExtensions.<>c__DisplayClass421.b__41(IDbCommand dbCmd) 在 C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\OrmLiteWriteConnectionExtensions.cs:ServiceStack.OrmLite.ReadConnectionExtensions.Exec( IDbConnection dbConn, Action 1 filter) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\Expressions\ReadConnectionExtensions.cs:line 55 at ServiceStack.OrmLite.OrmLiteWriteConnectionExtensions.Insert[T](IDbConnection dbConn, T[] objs) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\OrmLiteWriteConnectionExtensions.cs:line 164 at ServiceStack.ServiceInterface.Auth.OrmLiteAuthRepository.<>c__DisplayClass5.<CreateUserAuth>b__4(IDbConnection db) at ServiceStack.OrmLite.OrmLiteConnectionFactoryExtensions.Run[T](IDbConnectionFactory connectionFactory, Func2 runDbCommandsFn) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\OrmLiteConnectionFactory.cs:ServiceStack.ServiceInterface.Auth.OrmLiteAuthRepository.CreateUserAuth(UserAuth newUser, String password) 在 ServiceStack.ServiceInterface 的第 171 行.Auth.RegistrationService.OnPost(注册请求)在ServiceStack.ServiceInterface.RestServiceBase`1.Post(TRequest请求)ClientConnectionId:55977ae9-775d-474f-a543-d4cdfeb66a0d}

我正在使用以下代码进行设置:

private void ConfigureAuth(Funq.Container container)
{
   ...
   //Create a DB Factory configured to access the UserAuth SQL Server DB
   var connStr = appSettings.Get("SQLSERVER_CONNECTION_STRING", //AppHarbor or Local connection string
   ConfigUtils.GetConnectionString("UserAuth"));
   container.Register<IDbConnectionFactory>(
                new AuthDBConnectionFactory(connStr, //ConnectionString in Web.Config
                SqlServerOrmLiteDialectProvider.Instance)
                {
                    ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                });

        //Store User Data into the referenced SqlServer database
    container.Register<IUserAuthRepository>(c =>
            new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

     var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
...
}

不久之后,我建立了一个与 Oracle 服务器上的空缺数据库的连接:

private void ConfigureVacancies(Funq.Container container)
{
...
var connStr = appSettings.Get ("VACANCIES_CONNECTION_STRING", //AppHarbor or Local connection string
            ConfigUtils.GetConnectionString("VacanciesDB"));

var dbFactory = (OrmLiteConnectionFactory)container.Resolve<IDbConnectionFactory>();

dbFactory.RegisterConnection("vacancies",  connStr, ServiceStack.OrmLite.Oracle.OracleDialect.Provider);
...
}

与 vacancies 数据库的连接工作正常,但是当我尝试在 auth 数据库上注册用户时,出现上述错误。在我看来,它正在坚持甲骨文方言?

4

1 回答 1

0

我发现在连接工厂中使用了 autodispose 连接来设置 setGlobalConnection 变量:

public void RegisterConnection(string connectionKey, string connectionString, IOrmLiteDialectProvider dialectProvider, bool autoDisposeConnection = true)
{
        NamedConnections[connectionKey] = new OrmLiteConnectionFactory(connectionString, autoDisposeConnection, dialectProvider, autoDisposeConnection);
}

这是故意的吗?我修改了我的代码,将 autoDisposeConnection 设置为 False,这解决了我的方言问题并允许服务堆栈查询 Oracle 和 MS SQL。我还没有完全弄清楚将 autoDisposeConnection 设置为 false 的后果是什么。我所有的测试现在都通过了!

于 2012-12-09T08:19:39.467 回答