Database Connection String error - oracle

Currently I am running MVC project using Oracle as my database.
When my solution runs, it throws the exception:
'entitycommandexecutionexception'.
I thought my webconfig file has some issues, so I looked in my webconfig. When I tried to save it, my file was saved with the an error message
"The 'data source' keyword is not supported".
My webconfig connectionstring is as follow:
<connectionStrings>
<add name="bob" connectionString="metadata=res://*/Entities.bob.csdl|res://*/Entities.bob.ssdl|res://*/Entities.bob.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=localhost/XE;PASSWORD=bobsamuel;PERSIST SECURITY INFO=True;USER ID=bobsamuel"" providerName="System.Data.EntityClient" />
</connectionStrings>

Your connection string is wrong. Pay attention on "providerName" part. Your's currently set to "System.Data.EntityClient" but it should be "Oracle.ManagedDataAccess.Client" - if you are using official Oracle driver.

Related

'The ADO.NET provider with invariant name 'Devart.Data.Oracle' is either not registered in the machine or application config file

Ok, there already is a similar issue. It is, however not exactly the same and the solution I got was not derived from the other issue's solution.
Here's my Web.Config setup:
<connectionStrings>
<add name="ADOEntities" connectionString="metadata=res://*/ADOModel.csdl|res://*/ADOModel.ssdl|res://*/ADOModel.msl;provider=Devart.Data.Oracle;provider connection string="User Id=dbUser;Password=*****;Server=oracleserver;Persist Security Info=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
Everything runs fine on my machine (sic), but when I tried to set the ws up on the quality server, I got the error on the title.
I got it working by following the steps in this ADO.NET link. Particularly,
You need to remove the defaultConnectionFactory registration and to add the Entity Framework provider registration by registering it in the entityFramework section
So the line defaultConnectionFactory must go
<entityFramework>
<providers>
<provider invariantName="Devart.Data.Oracle" type="Devart.Data.Oracle.Entity.OracleEntityProviderServices, Devart.Data.Oracle.Entity.EF6, Version=9.6.696.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</providers>
</entityFramework>
Then, add the System.Data section. In my case it looks like this:
<system.data>
<DbProviderFactories>
<remove invariant="Devart.Data.Oracle" />
<add name="dotConnect for Oracle" invariant="Devart.Data.Oracle" description="Devart dotConnect for Oracle" type="Devart.Data.Oracle.OracleProviderFactory, Devart.Data.Oracle, Version=9.6.696.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</DbProviderFactories>
</system.data>
If that still doesn't do the trick for you -- And it didn't for me -- try adding the following line to your context class:
[DbConfigurationType(typeof(Devart.Data.Oracle.Entity.OracleEntityProviderServicesConfiguration))] //Add this line
public partial class ADOEntities : DbContext
You might want to create a partial class, incase you're using ADO, Devart, or other auto-generated entity model, to avoid having this piece of code in an auto-generated class

Transforming an LDAP connection string to an Oracle ODP.NET Managed web.config <LDAPSettings />

The not-very-patient DBA in my group has given me a string similar to the following as my LDAP connection string -
jdbc:oracle:thin:#ldap:/oidAAA.ourdomain.com:4444/foo,cn=OracleContext,dc=bardb
And according to the Oracle Documentation:
For OID, all ldap.ora parameters must be set with valid values to
complete configuration.
I have found a list of "all ldap.ora parameters" but I've yet to deduce which parts of the above connection string map to which parameters.
Thanks to some help from the DBA, I've been able to determine the following:
<LDAPSettings>
<LDAPSetting name="DIRECTORY_SERVERS" value="oidAAA.ourdomain.com:4444" />
<LDAPSetting name="DIRECTORY_SERVER_TYPE" value="OID" />
<LDAPSetting name="DEFAULT_ADMIN_CONTEXT" value="bardb" />
</LDAPSettings>
The question I have now is how to actually USE this. Assuming my database is "foo" how do I use ODP.NET to resolve this?
Any assistance would be greatly appreciated.
I assume you have enabled the config parsing
<configuration>
<configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=[...], Culture=neutral, PublicKeyToken=[...]"/>
[...]
Now you need to specify your connection string
<configuration>
<connectionStrings>
<add name="myFooConnection" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=[...];Password=[...];Data Source=foo"/>
Note the Data Source=foo part. It uses the configured TNS, LDAP etc. to resolve the connection.
You can reference the connection by name myFooConnection with compatible ASP.Net controls or directly pass the connection string to an Oracle.ManagedDataAccess.Client.OracleConnection
VB.Net:
Dim connectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("myFooConnection").ConnectionString
Dim connection As New Oracle.ManagedDataAccess.Client.OracleConnection(connectionString)

how to deploy asp.net mvc 3 where LINQ to SQL Classes is used?

i'm new in LINQ.I have used LINQ to SQL class in my asp.net mvc 3.now when it comes to deployment in iis how can i manage connection ?i'm stuck here.help plz ,thankx in advance
Are you managing the connection via Web.config?
<connectionStrings>
<remove name="MyConnectionString"/>
<add name="MyConnectionString" connectionString="XXXXXXXXXX"
providerName="System.Data.SqlClient" />
</connectionStrings>
You should verify that the connectionStrings is pointing to the right SQL server
edit-1
Just to be sure we are on the same page on "managing the connection via Web.config" I mean via the partial class:
public partial class MyDataContext{
public MyDataContext()
: base(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString,mappingSource)
{
}
}
And of course you need to change also:

Entity Framework - Connection string - Keyword not supported 'Data Source'

I know this is a common issue faced by beginners in EF and there have been multiple questions and answers on the same here, but still I have not been able to still resolve the issue.
I am using EF 4.1 and MVC 3 and have generated the EF model from the DB in a separate library. I have copied the connection string from the app.config in the supporting library to the web.config of my application. I am also instantiating the object context by passing the web.config connection string.
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MasterDataContainer"].ConnectionString;
context = new MasterDataContainer(connectionString);
The connection string in web.config is as below
<connectionStrings>
<add name="MasterDataContainer" connectionString="metadata=res://*/MasterData.csdl|res://*/MasterData.ssdl|res://*/MasterData.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=MasterData;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I am getting the error "Keyword not supported : data source".
Any help on this is appreciated.
You don't need the EntityConnectionStringBuilder since you already have an EF connection string. i.e. just
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MasterDataContainer"].ConnectionString;
context = new MasterDataContainer(connectionString);
EntityConnectionStringBuilder can be used to build up an EF connection from e.g. a vanilla .NET one.
Edit
It looks like you've encountered this problem here. The workaround is to escape the load the connection string and then replace the " with "'"
What might be easier altogether is to use the name=ConnStringName overload of ObjectContext / DbContext. In your case, this would be
context = new MasterDataContainer("name=MasterDataContainer");
Note also if you view the source of the generated Context (probably MasterDataContainer.Context.cs) that the default constructor should have the EntityContainerName property hardcoded into it, so you might not need to provide a connectionstring at all to the constructor, provided that you keep the same EntityContainerName.
http://msdn.microsoft.com/en-us/library/bb739017.aspx
easiest way to solve this issue is rewrite your EF conn string (replacing the amp; and quot;):
from ORIGINAL
<add name="Entities" connectionString="metadata=res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl;provider=System.Data.SqlClient;provider connection string="metadata=res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=<SERVER\INSTANCE>;initial catalog=<BDD>;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"" providerName="System.Data.EntityClient" />
to FIXED
<add name="Entities" connectionString="metadata=res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl;provider=System.Data.SqlClient;provider connection string='metadata=res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl;provider=System.Data.SqlClient';provider connection string='data source=<SERVER\INSTANCE>;initial catalog=<BDD>;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework;'" providerName="System.Data.EntityClient" />
Just change then Entities name and the tags SERVER\INSTANCE and BDD with your values and that's it.
I hope this saves you a few days of research. Enjoy!

publishing Db after creating using EF Code first

I have created a project in MVC 3 using code first and nugget ,
And I would like to clear a few thing before publishing to my shared hosting:
In my project I have a class name: IchudShulContext (IchudShul is my project name)
In my sql server express it has created a DB name: IchudShul.Models.IchudShulContext.dbo
Does it make a different what name I give my shared hosting DB ?
Or should it match one of the following : IchudShul / IchudShulContext
My local connectionStrings look like this :
connectionString="Data Source=MyPc-MAINPC\SQLEXPRESS;Initial Catalog=IchudShul.Models.IchudShulContext;Integrated Security=True"
providerName="System.Data.SqlClient" />
Thanks
Based on Code-First convention, Your ConnectionString name in your web.config should have the same name as your context. Database name is not important. in your scenario, in your web.config:
<connectionStrings>
<add name="IchudShulContext" providerName="System.Data.SqlClient"
connectionString="Data Source=MyPc-MAINPC\SQLEXPRESS;Initial Catalog=WHATEVER_YOUR_DB_NAME_IS;Integrated Security=True" />
</connectionStrings>
If you want to use conventions, make sure the name attribute is: IchudShulContext. That's all. Fill in WHATEVER_YOUR_DB_NAME_IS with whatever you db name is.
Your shared hosting DB can be named anything.
Your ConnectionString should be updated needs to be updated to point to your database. What that is, you will need to know from your shared hosting provider.
you can name you DB anything, as long as it is valid with respect to your DBMS. the only this that should be matched with your datacontext name is connection name in connection strings section of your web.config file.

Resources