Through using Visual Studio to learn more about ASP.net and VB.net I would like to connect to a database. I create an .mdf database file but I've no idea how to connect to it (well, I have some code below...) that's not my only problem but I'll ask the next question in a moment. The code I'm using is shown below, am I missing something? Or using the wrong connection string?
Private Function sqlDBConnection() As Boolean
'Set the variables
Dim SQLConnectionString As String
Dim SQLConnection As New SqlConnection()
'Create the Connection String
SQLConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=\App_Data\Overland.mdf;Initial Catalog=Overland;Integrated Security=True;User Instance=True"
'Set the connection string into the SQL connection
SQLConnection.ConnectionString = SQLConnectionString
'Open up the connection
SQLConnection.Open()
End Function
A similar connection string works ( "Data Source=LAMBDA\SQLEXPRESS;Initial Catalog=General;Integrated Security=True"
) with an actual database server (SQL Express 2005) but modifying it a bit doesn't work for an SQL Server file (.mdf in this case) so if you have any idea please help :)
Secondly as you can see I've got the function set as a Boolean, however I don't return anything and the .Open() function doesn't return anything. Therefore how can I check to see whether a connection is succesful or not before it breaks out into an error? I'd like to be able to catch it just incase.
Thanks for your time.