ORMLite方言

时间:2012-12-04 21:40:47

标签: ormlite-servicestack

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

  

{System.Data.SqlClient.SqlException(0x80131904):无效的对象名称'dual'。     在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action 1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 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 stateObj,Boolean&amp; 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.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async,Int32 timeout,Task&amp; task,Boolean asyncWrite)     在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String方法,TaskCompletionSource 1 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, IList 1 insertFields,IDbCommand dbCommand)     at 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__DisplayClass42 1.b__41(IDbCommand dbCmd)在C:\ src \ ServiceStack.OrmLite \ src \ ServiceStack.OrmLite \ OrmLiteWriteConnectionExtensions.cs:第164行     at 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, Func 2 runDbCommandsFn)在C:\ src \ ServiceStack.OrmLite \ src \ ServiceStack.OrmLite \ OrmLiteConnectionFactory.cs:第171行      at ServiceStack.ServiceInterface.Auth.OrmLiteAuthRepository.CreateUserAuth(UserAuth newUser,String password)     at ServiceStack.ServiceInterface.Auth.RegistrationService.OnPost(注册请求)     at ServiceStack.ServiceInterface.RestServiceBase`1.Post(TRequest request)   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);
...
}

与空缺数据库的连接工作正常,但是当我尝试在auth数据库上注册用户时,我得到上面的错误。在我看来,它正在持有Oracle方言?

1 个答案:

答案 0 :(得分:0)

我发现连接工厂中正在使用自动中断连接来设置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的后果是什么。我的所有测试现在都在过去了!