use multiple Connection for Oracle database

3 posts, 0 answers
  1. Saeid
    Saeid avatar
    7 posts
    Member since:
    Jan 2012

    Posted 18 Oct 2014 Link to this post

    Hi
    I want use multiple connection string according user selection, and connect data model to selected database.
    So I have:

    public class HomeController : Controller
        {
            // GET: Home
            public ActionResult Index()
            {
               string orcleTestConnection = @"data source=orcl_test;password=*****;user id=user1;";
     
                using (var db = new EntitiesModel1(orcleTestConnection))
                {
                    var model = db.Xtests.Select(p => p);
                }
                return View(model );
            }
        }


    With default connection (without set new connection string) everything work fine, but when I set
    connection string I got this error:

    {"System.InvalidCastException: Specified cast is not valid.
       at Oracle.ManagedDataAccess.Client.OracleDataReader.GetString(Int32 i)
       at OpenAccessRuntime.Data.VariableLengthStringConverter.Read(DataHolder& data)
       at OpenAccessRuntime.Relational.metadata.RelationalColumn.GetValue(DataHolder& data)
       at OpenAccessRuntime.Relational.RelationalGenericOID.CopyKeyFields(DataHolder& data)
       at OpenAccessRuntime.Relational.fetch.FopGetOID.fetch(FetchResult fetchResult, StateContainer stateContainer)
       at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)
    Processing 0: MultiDomainWebApplication1.Xtest [0] System.InvalidCastException: Specified cast is not valid.
       at Oracle.ManagedDataAccess.Client.OracleDataReader.GetString(Int32 i)
       at OpenAccessRuntime.Data.VariableLengthStringConverter.Read(DataHolder& data)
       at OpenAccessRuntime.Relational.metadata.RelationalColumn.GetValue(DataHolder& data)
       at OpenAccessRuntime.Relational.RelationalGenericOID.CopyKeyFields(DataHolder& data)
       at OpenAccessRuntime.Relational.fetch.FopGetOID.fetch(FetchResult fetchResult, StateContainer stateContainer)
       at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)"}


  2. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 21 Oct 2014 Link to this post

    Hi Saeid,

    Could you validate that connection string you are using is with exactly the same format with the one in the application cofig file which you mentioned is working well?

    In general the only difference is that Telerik Data Access will read the connection string from the config file and then the procedure is the same as you would pass it in the context constructor. That is why I suppose there is any difference in the connection strings in both cases.
    I can see from the exception stack trace that the managed Oracle driver is used but I cannot see this in the connection string. Most probably you should add the provider in the connection string too, something like: providerName="Oracle.ManagedDataAccess.Client.


    For more information:
    How to: Consume ODP.NET Oracle, Managed Driver

    I hope this helps. 

    Regards,
    Kaloyan Nikolov
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
  4. Lawrence
    Lawrence avatar
    1 posts
    Member since:
    Sep 2016

    Posted 13 Sep in reply to Kaloyan Nikolov Link to this post

    Saeid and Kaloyan,

    You cannot get that error message until data is read from the model therefore connection strings are not a valid place to troubleshoot this problem.

     

     

     

Back to Top