-1

I want to put my connection string on a USB dongle lock and make my app to read connection string from the lock. But I don't know how to pass the string to ado.net and the connection string placed on app.config.(I'm using ado.net)The following code is my connection string tag:

      <connectionStrings><add name="Db_ReceptionEntities1" connectionString="metadata=res://*/Model.DBReception.csdl|res://*/Model.DBReception.ssdl|res://*/Model.DBReception.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=Db_Reception;user id=sa;password=******;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
Ankit Singh
  • 272
  • 5
  • 15

2 Answers2

0

How to put string as connection string to app.config?

You do not need to read from the dongle and put it into app.config. You can just read from the dongle and give the connection string to your context.

Your connection string looks like an EF database first connection string. The DbContext class has a constructor which accepts a connection string name or a full connection string. You can use that and pass the connection string to it.

Create your context like this:

public class StackContext : DbContext
{
    public StackContext(string connection) : base(connection)
    {

    }
}

Then read the connection string from the dongle and pass it to your context like this:

// read from dongle
var connectionString = ...;
var ctx = new StackContext(connectionString);
CodingYoshi
  • 25,467
  • 4
  • 62
  • 64
-1

this helped:

   public Db_ReceptionEntities1(string x)
        : base("name=Db_ReceptionEntities1")
    {

        Database.Connection.ConnectionString = x; 
    }