This is a migrated thread and some comments may be shown as answers.

use multiple Connection for Oracle database

2 Answers 146 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Saeid
Top achievements
Rank 1
Saeid asked on 18 Oct 2014, 08:55 AM
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 Answers, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 21 Oct 2014, 11:37 AM
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.
 
0
Lawrence
Top achievements
Rank 1
answered on 13 Sep 2016, 08:15 PM

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.

 

 

 

Tags
General Discussions
Asked by
Saeid
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Lawrence
Top achievements
Rank 1
Share this question
or