I've written an app using the RSSBus QB ADO.net provider - VS 2010 and .net 4.0. I'm connecting to QB with the entityframework 6 and using linq.
I'm dynamically changing the connectionstring in order to manipulate the offline cache. Everything works great.
I've migrated the app to VS 2013 with .net 4.5. In vs2010/4.0 the QB entity object is of ObjectContext and in vs2013/4.5 the QB entity is of DbContext and I don't have the connectionstring property available.
Is there any other methodology to manipulate the cache settings on the connection?
DbContext does not directly have a Connection property but it does have Database which does contain a Connection object which should allow you to edit the connection string:
https://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext%28v=vs.113%29.aspx
There's another method you can use involving a partial class shown here:
EF 5 Changing Connection String at Runtime
Related
I have an application that I used to connect to a mySQL database. I have installed the MySQL.Data package and I use this code to build my connection:
services.AddScoped<System.Data.IDbConnection>((s) =>
{
IDbConnection conn = new MySqlConnection(Configuration.GetConnectionString("databasename"));
conn.Open();
return conn;
});
This works fine as I am able to read/write data from the database.
Now, I need to have the same application access a MS SQL database. The tables are all the same and the fields on each table are the same as well. I am having a hard time finding what I should change my code to (or what package I should include). When I remove the MySQL.Data package, the MySqlConnection function becomes invalid (as would be expected).
Any idea what package to include and what function to use to establish the connection?
Any assistance is greatly appreciated.
Thank you!
EDIT #1
I found an old stackoverflow post (I should have referenced it here but I closed the window) that talks about this very issue. The suggestion was to add
using System.Data.SqlClient;
and then change the assignment code to
IDbConnection conn = new SqlConnection(Configuration.GetConnectionString("databasename"));
I made these changes and now I get this error within the code:
Im at a loss as to how to resolve this. I verified that my project is in framework .NET core 3.1
Not sure about size of your project and detailed requirements but I would suggest to use libraries like:
Entity Framework - no SQL knowledge needed, can connect to any Db technology, almost no code changes required when switching between Db providers
or
Dapper - fast lightweight also supports multiple Db providers but you need to write correct SQL commands yourself specific for each Db technology you use
I have followed the example from Microsoft documentation for a simple code first approach on a .NET Framework database generation. I checked my data source and confirmed it works as when I go to add a new data connection via Microsoft SQL Server the name of my configuration File shows up under the drop down for available tables.
When I test the connection to my table I get a successfully response.
When I click to add the new data connection I get the following error:
Previously I was able to connect to some other local databases like Northwind and other simple test databases, but not when ever I try to connect to any db I get this error. I tried in a VM as well and still get the same error.
Any suggestions?
EDIT: connection string:
connectionString="data source=(LocalDb)\MSSQLLocalDB;initial catalog=Proj.TestDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
EDIT 2: When running a query in SQL Server Management Studio, I am able to see the generated tables and can even see how the code populated them (I had a simple add statement as a test). But for some reason I can not add it as a db connection in Visual Studio 2019
We have a DB2 database which we are accessing via EF. We are able to connect to the database and do read & write operations as part of this.
Now the plan is to initialize the DB using
Database.SetInitializer(new CreateDatabaseIfNotExists<CustomContext>())
This throws out an error saying
HResult=-2146232032
Message=CreateDatabase is not supported by the provider.
Source=EntityFramework InnerException:
System.Data.Entity.Core.ProviderIncompatibleException
Previously we were connecting with
Database.SetInitializer(new NullDatabaseInitializer<CustomContext>());
and this was working fine.
The question is has any one tried creating a new DB2 database from within EF?
You cannot do that.That is Known limitation of the provider.
General limitations:
Only database-first scenarios are supported: any database object that
you reference in Entity Framework must first exist in the database.
Invocation of store-specific functions is not supported.
Trusted context connection properties that you set in the Server Explorer Add
Connection dialog are not passed to Entity Framework connections.
You can read it here : Limitations to Microsoft Entity Framework support
Migration is not supported by IBM EF provider implementation.
If you need DB2 migration support you can use this package that implements only migration (so you can use it in addition to IBM DB2 EF Provider)
https://www.nuget.org/packages/System.Data.DB2.EntityFramework.Migrations/
You can find more info here
https://db2ef6migrations.codeplex.com/
I have an old system which generated me a database in .CDB extension (i run on Firebird-1.5.6.5026-0-Win32) and i can access this database in IBExpert to query and stuff. But i need to write an application in .NET (VS 2010 4.0 framaework) so i can read this database and access some of the data to insert into a table inside SQLServer.
I tried many things, changed the server version and other things but i now all i get is ''Cannot find fbembed.dll'' exception error while trying to open the connection. My FB server doesnt have this file since he uses the 'fbclient.dll' already.
Any thoughts on how to connect my application to this .CDB database?
(this firebird version is the same that the legacy system is running, so i used the 1.7RC firebird .net provider within this server)
The connection string used is:
<add name="FirebirdConnectionString" connectionString="User=SYSDBA;Password=masterkey;
Database=localhost:C:\temp\BD\ECLECTIC.CDB;DataSource=localhost;Port=3051;
Dialect=3;Charset=NONE;Role=;Connection lifetime=15; Pooling=false;
MinPoolSize=0; MaxPoolSize=50; Packet Size=8192; ServerType=1;"
providerName="FirebirdSql.Data.FirebirdClient"/>
Unless you really want to use Firebird embedded (which you don't as you also specify localhost), you should not specify ServerType=1, but either leave it out entirely or set ServerType=0.
As to your other problem you mention in the comments, I suggest you check if this solves it and otherwise create a new question with more information.
I want to use Massive ORM(by Rob Conerys) in a WPF Application using Entity Framework.
It sais to add in app.config the providerName = 'System.Data.SqlClient'
but using EF I have System.Data.EntityClient and I get this error : "Unable to find the requested .Net Framework Data Provider. It may not be installed."
Any suggestions ?
You can solve this by creating a second connection string specifically for Massive.