What is the correct format of the Oracle connection string in MVC 6?
My dependencies:
"EntityFramework": "5.0.0",
"Oracle.ManagedDataAccess": "12.1.2400",
"Oracle.ManagedDataAccess.EntityFramework": "12.1.2400",
My connection string :
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Data Source=myHost:myPort/mydb;User Id=myUser;Password=myPassword"
}
}
}
Reported error:
{"An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct."}
In MVC 5 I use this:
<add name="DefaultConnection" connectionString="metadata=res://*/App.csdl|res://*/App.ssdl|res://*/App.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=myHost:myPort/myDb;PASSWORD=myPassword;PERSIST SECURITY INFO=True;USER ID=myUser;Connection Timeout=900"" providerName="System.Data.EntityClient" />
In your Example your are using Managed Driver as Data Provider to use oracle DB.
But in your EF connection string your are mentioning different Provider (providerName="System.Data.EntityClient") while you should use (providerName="Oracle.ManagedDataAccess.Client")
See correct connection string below :
<add name="TestContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=test;Password=testpassword;Data Source=eftest" />
For more details Please refer to the following link :
https://docs.oracle.com/cd/E56485_01/win.121/e55744/InstallEntityConfig.htm#ODPNT8266
Related
I realize there's similarly titled posts here, I've searched through all of them without finding my solution.
I'm uploading an Excel file to SQL Server in ASP.net MVC. Here's my connection string:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication12-20180107114522.mdf;Initial Catalog=aspnet-WebApplication12-20180107114522;Integrated Security=True;" providerName="System.Data.SqlClient" />
And here's my Excel file connection string:
string constr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", filepath);
The rest of my code uses SqlConnection / SqlCommand etc, rather than oleDB commands.
You use SqlConnection to connect to SQL Server databases. That connection type doesn't understand "Provider" in the connection string.
You need to use the appropriate connection type for Jet databases, e.g. OleDbConnection.
Ive been working on a web app for the past month and now its time to deploy it on real windows server.The problem is once i deployed it my default localdb code first SQL database no longer works with this code:
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
)]
Source Error:
Line 11: var manager = new UserManager();
Line 12: var user = new ApplicationUser() { UserName = UserName.Text };
Line 13: IdentityResult result = manager.Create(user, Password.Text);
Line 14: if (result.Succeeded)
Line 15: {
my web.config string :
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346;AttachDbFilename=|DataDirectory|\aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
Its so frustrating im kinda lost , i dont want to build my login and registration from scratch i just want to use the provided ones from Visual Studio 2017 and there is no tutorial up to date how to do it.
I have SQL Express on my computer installed and its currently running.
There are possible solutions to solve LocalDB instance issue:
1) If the database is already created (as given by AttachDbFilename=|DataDirectory|\aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346.mdf), remove the section so that it only contains Initial Catalog shown below.
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
2) Set IIS application pool for the MVC application to either LocalSystem or NetworkService from ApplicationPoolIdentity - if you suspect a permission-related issue for the application.
3) Find out \%WinDir%\System32\inetsrv\config\applicationHost.config file and enable setProfileEnvironment="true" (restart the application pool afterwards):
<!-- use application pool name depending which pool that your MVC site used -->
<add name="DefaultAppPool" ...>
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
Further references:
SQL Server Connection Strings
Using LocalDB with Full IIS Series: (Part 1) (Part 2)
Similar issue:
Deployment of SQL Express LocalDB on IIS
I've been spinning my wheels on this for awhile now and haven't been able to find anything substantial on the topic.
I've implemented an MVC 6 project that is utilizing the Identity Framework 2 and Entity Framework 6. The application works fine with a local database being used as my identity repository. On the first connection, the Entity Framework creates the identity tables based on my identity model classes. I built it based off of a project from this book. The chapters on using Identity and all of the online samples I find don't cover pointing the entity framework to a remote database.
Here are my connection strings I've experimented with...
Local database connection string. Project works fine.
<add name="IdentityDb" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\IdentityDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
Failed approach 1. I based this off of other connection strings from my other projects. I removed the meta data parameters because when it comes to my understanding, this points to the edmx file but I don't have one since I'm taking a code first approach and letting identity and the entity frameworks build the database. I'm wondering if I'm missing something here because I've always taken a database first approach until now.
<add name="IdentityDb" connectionString="provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=IdentityTest;Uid=*****;Pwd=*****;integrated security=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Returned exception details. The metadata keyword is missing.
System.ArgumentException: Some required information is missing from the connection string. The 'metadata' keyword is always required.
Failed approach 2. I built an empty Identity.edmx file thinking this must be where all of the metadata is stored and maybe the entity framework will update it and have it's required resources once the app connects to the database the first time.
<add name="IdentityDb" connectionString="metadata=res://*/Identity.csdl|res://*/Identity.ssdl|res://*/Identity.msl;provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=IdentityTest;Uid=****;Pwd=****;integrated security=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Returned exception detail. The meta data is missing.
System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource.
Last failed approach. I found a lot of online sources where people simply changed the metadata parameters to "res://*". I'm guessing this is some kind of wildcard that would locate the metadata resources if they existed...
<add name="IdentityDb" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=IdentityTest;Uid=****;Pwd=****;integrated security=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Returned exception details (With a identity.edmx file in the project)
System.NotSupportedException: Model compatibility cannot be checked because the DbContext instance was not created using Code First patterns. DbContext instances created from an ObjectContext or using an EDMX file cannot be checked for compatibility.
Returned exception details (Without an identity.edmx file in the project)
System.ArgumentException: Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied
My database context class
public class AppIdentityDbContext : IdentityDbContext<AppUser>
{
public AppIdentityDbContext() : base("name=IdentityDb") { }
static AppIdentityDbContext()
{
// Seeds the database when the schema is first created through the Entity Framework.
Database.SetInitializer<AppIdentityDbContext>(new IdentityDbInit());
}
// OWIN uses this method to create instances of this class when needed.
public static AppIdentityDbContext Create()
{
return new AppIdentityDbContext();
}
public System.Data.Entity.DbSet<UAM.Models.Identity.AppRole> IdentityRoles { get; set; }
}
// Seed class for initially populating the identity database.
public class IdentityDbInit : DropCreateDatabaseIfModelChanges<AppIdentityDbContext>
{
protected override void Seed(AppIdentityDbContext context)
{
PerformInitialSetup(context);
base.Seed(context);
}
public void PerformInitialSetup(AppIdentityDbContext context)
{
// Initial database configuration
}
}
Any help or insight would be much appreciated. What is the correct approach for doing this? Is there something that I need to do when I transition from using a local database to a remote one? Let me know if I should provide anymore code samples. I'm fairly new to MVC and am currently building this module so that I can use it for a few enterprise applications that I'll be developing this year.
You need to specify providerName="System.Data.SqlClient" instead of providerName="System.Data.EntityClient"
For Example
<add name="IdentityDb" connectionString="Data Source=*******;Database=IdentityTest;Integrated Security=false;User ID=**;Password=******;" providerName="System.Data.SqlClient"/>
This is the connection string I use and it worked without an issue.
<add name="InventoryEntities"
connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlinstance;initial catalog=DBName;persist security info=True;user id=UID;password=PWD;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
The tool generated this for me (I didn't need to do anything custom to the connection string) so maybe you can delete and let the too re-add it? (I think it does that)?
Also, you didn't rename the EF files at all did you? If you did, you would have to update the connection string to match.
I have a connection string in my web.config file like this
<add name="ModelDbContext"
connectionString="metadata=res://*/Models.DizlyModel.csdl|res://*/Models.DizlyModel.ssdl|res://*/Models.DizlyModel.msl;provider=System.Data.SqlClient;provider connection string="data source={Server},1433;initial catalog=Dizlybeta;user id={id};Password={Password};MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
but then I go to my hosted azure website and place this as connection
And then I replace the hidden security with
metadata=res://*/Models.DizlyModel.csdl|res://*/Models.DizlyModel.ssdl|res://*/Models.DizlyModel.msl;provider=System.Data.SqlClient;provider connection string="data source={Server},1433;initial catalog=Dizlybeta;user id={id};Password={Password};MultipleActiveResultSets=True;App=EntityFramework"
but it still doesn't work, can anyone help me with how to place the right connection string in the website configuration?
Something to try:
Use a SqlClient connection string instead of an EntityClient connection string.
In that case, you'll probably need to pass the name of the connection string to the DbConext constructor, which you can do in one place like:
public MyDbContext : base("sqlClientConnectionStringName")
{
}
You might also need to ensure a SqlClient provider exists. Check the docs for more.
strong textI'm attempting to run the MVC Movie Project, located here:
http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/accessing-your-models-data-from-a-controller
When I attempt to run it, I'm given an error in the MoviesController.cs:
public ActionResult Index()
{
return View(db.Movies.ToList());
}
Which states: Invalid value for key 'attachdbfilename'.
I researched this and discovered some people has success by changing the connectionString "MovieDBContext" value from this:
<add name="MovieDBContext"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"
/>
to this:
<add name="MovieDBContext"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"
/>
That seems to let it run further, but then it errors out again at the same place in MoviesController.cs ...
public ActionResult Index()
{
return View(db.Movies.ToList());
}
with a new error:
"An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct."
I did a search looking for suggestions to what this was, including these posts:
System.Data.Entity.Core.ProviderIncompatible Exception in MVC 5
An unhandled exception occurred during the execution of the current web request, "Не найден указанный модуль"
It would suggest that my "Movies.mdf" file is missing, but when I check the App_Data folder its there. One person suggested recreating LocalDB, I'm not sure what that is or how I'd do that. As you can tell I'm very new to .NET. Any suggestions are very much appreciated. Thank you for reading.