0

I have been searching the web since yesterday but cannot find an example which may solve my issue.

I am trying open and close the connection manually with the below code

        Using conn = New EntityConnection(entityBuilder.ToString)

            Using ctx As New EbosEntities()

                 conn.Open()

The problem is, how do i write a constructor(Entity Class) which will take the conn as parameter? otherwise this connection will have nothing to do with the (new context) declaration, I guess. Like below,

           ctx As New EbosEntities(conn)

If I want to use default connection string can I just write

           ctx.Database.Connection.Open()

Many Thanks.

Anup
  • 115
  • 5
  • 15

1 Answers1

2

I don't know how to do it on VB, but with C# you can try to do something like this:

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

    }
    finally
    {
        datacontext.Connection.Close();
    }
Oleksii Aza
  • 5,368
  • 28
  • 35
  • Thanks Alexey, what is the difference between conn.Open() and ctx.Database.Connection.Open(). – Anup Sep 24 '13 at 23:02