0

I have a few projects (I'm trying to connect to a local DB):

  1. DB_API project (C# project) using EF to connect to DB
  2. NativeCallingCLR.MixedDLL (C++/CLI) - IL bridge to invoke C# DB API methods
  3. NativeCallingCLR.Native (C++) - Implementing the API from C++/CLI to connect to the DB

This project structure is based on: https://www.codeproject.com/Articles/35041/Mixing-NET-and-native-code

I'm trying to configure EF to connect not with running assembly configurations but with other configurations/ Create a config file to the native c++ project.

I have tried to configure the connection like this:

Creating a class structure like this:

public partial class ABC : DbContext
{
    public ABC(DbConnection conn) : base (conn,true)
    {

    }
}

And then creating the DbConnection object like this:

public int CreateConnection(string DBConnectionString, string DBProviderName)
{
    var conn = DbProviderFactories.GetFactory(DBProviderName).CreateConnection();
    conn.ConnectionString = DBConnectionString;
    db = new ABC(conn);
    return _PASS;
}

And I'm calling CreateConnection with these arguments:

DBConnectionString="metadata=res://*/InDBM.csdl|res://*/InDBM.ssdl|res://*/InDBM.msl;provider=System.Data.SqlClient;provider connection string='data source=localhost;initial catalog=Mycatalog;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'"

DBProviderName="System.Data.EntityClient"

These arguments worked fine when I have tried to connect with an app.config and a C# running assembly but when I have tried to connect with creating the Dbconnection object this method failed.

Anybody have idea what I'm doing wrong here?

Or Groman
  • 123
  • 1
  • 11

1 Answers1

0

Ok, seems like I wasn't really understanding what I'm doing.

This stackoverflow post solved the problem for me:

How do I programmatically set the connection string for Entity-Framework Code-First?

Community
  • 1
  • 1
Or Groman
  • 123
  • 1
  • 11