Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Did you try the <code>Database</code> property?</p> <pre><code>GumpIndexDatabase.Database.Connection.ConnectionString = "your conn string"; </code></pre> <p>I just tested it <strong>very short</strong>, so no guarantee it works without problems. But I was successful using it in the contructor of one of my service layer classes:</p> <pre><code>public class MyService { protected DataContext DataContext { get; set; } public MyService(DataContext dataContext) { DataContext = dataContext; DataContext.Database.Connection.ConnectionString = "conn string"; } } </code></pre> <p>Just saw that <code>DbContext</code> has an overload <code>DbContext(string nameOrConnectionString)</code>. You should be able to use this too.</p> <h2>Using an existing connection</h2> <p>Or you use an existing connection. Your <code>DbContext</code> should have something like this:</p> <pre><code>public class DataContext : DbContext { public DataContext(DbConnection existingConnection) : base(existingConnection, true) { } } </code></pre> <p>And then initialize it whereever you need to:</p> <pre><code>public void SomeMethod() { var connString = "whatever"; // could also be something like Textbox1.Text using (var connection = new SqlConnection(connString)) { var context = new DataContext(connection); } } </code></pre> <p>Of course <code>SqlConnection</code> can be anything that inherits from <code>DbConnection</code>. See <a href="http://msdn.microsoft.com/de-AT/library/system.data.common.dbconnection.aspx" rel="nofollow">DbConnection Class</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload