Manually open and close connection with entity framework

connection entity-framework explicit

Question

Since yesterday, I've been looking online for examples that would help me with my problem, but I've come up empty-handed.

I'm attempting to manually open and close the connection using the code below.

        Using conn = New EntityConnection(entityBuilder.ToString)

            Using ctx As New EbosEntities()

                 conn.Open()

The issue is how to create an entity class constructor that takes a conn as a parameter. If not, I believe the (new context) declaration won't have anything to do with this connection. as seen below

           ctx As New EbosEntities(conn)

Can I just type "default connection string" if that's what I want to do?

           ctx.Database.Connection.Open()

Thank you.

1
0
9/21/2013 9:00:56 AM

Popular Answer

I'm not sure how to implement it in VB, but you might attempt something similar in C#:

    var datacontext = new EbosEntities();
    try
    {                
        datacontext.Connection.Open();
        //do some work

    }
    finally
    {
        datacontext.Connection.Close();
    }
2
9/21/2013 9:08:09 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow