davecocks
asked on
Open .MDF Sql sever connection VB.Net
HI,
I'm building a windows forms application in Visual Studio 2008. I've set-up a SQL server 2008 .MDF database and attached it to my project. All the data is stored, used, shown etc and seems to work fine.
However, when I debug the project (for the first time!) or publish it I get a' timeout expired' error.
I think it is becuase I haven't explicity opened the connection to the database in code.
If I check the .MDF properties before and after I manually click the database in the Server Explorer, I can see that the database properies 'State' changes from closed to open and then I don't get the error. However, I need to fix for publishing.
How do I open this connection in VB.Net? ( .Net 3.5 )
Thanks
I'm building a windows forms application in Visual Studio 2008. I've set-up a SQL server 2008 .MDF database and attached it to my project. All the data is stored, used, shown etc and seems to work fine.
However, when I debug the project (for the first time!) or publish it I get a' timeout expired' error.
I think it is becuase I haven't explicity opened the connection to the database in code.
If I check the .MDF properties before and after I manually click the database in the Server Explorer, I can see that the database properies 'State' changes from closed to open and then I don't get the error. However, I need to fix for publishing.
How do I open this connection in VB.Net? ( .Net 3.5 )
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
'Opens SQL connection
'Prevents the timeout exception error
'I put it on the load of each form
Dim cn As New SqlClient.SqlConnection(My
If cn.State = ConnectionState.Broken OrElse cn.State = ConnectionState.Closed Then
'reopen your connection:
cn.Open()
End If
PS. the database was called 'internal.mdf'