Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
nomadsoul
Yak Posting Veteran
89 Posts |
Posted - 2007-05-30 : 09:15:47
|
| Hi,I'm trying to learn the art of connecting, I'm having fun and makingprogress with the SQL Server connections but when it comes to Access connections I get problems. (using a vb.net form with a button to test connections)For example I'm trying to figure out the UDL thing and get this error:An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dllAdditional information: Object variable or With block variable not set.Wish I knew where to go from here. Can anyone point me to a solution?Button onClick code is below:thanksPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim objConn Dim connStr Dim Server objConn = Server.CreateObject("ADODB.Connection") connStr = "File Name=C:\conn.udl; " objConn.Open(connStr) Try objConn.Open() Catch connError As Exception MessageBox.Show(connError.Message, "Connection Error") End Try MessageBox.Show(objConn.State) If objConn.State = 1 Then Me.Text = "Welcome to the videoRental DB!" End If End SubIt is better to be prepared and not have an opportunity than to not be prepared and have an opportunity |
|
|
rudesyle
Posting Yak Master
110 Posts |
Posted - 2007-05-30 : 16:23:16
|
| Instead of referencing the vb dll, and using outdated methods, why don't you just use ado.net ? Also, looks like you call the Open method twice? Do a google search on ado.net quickstarts. I think you'll understand things a bit more. |
 |
|
|
nomadsoul
Yak Posting Veteran
89 Posts |
Posted - 2007-05-30 : 19:57:01
|
| Ok I will thanksIt is better to be prepared and not have an opportunity than to not be prepared and have an opportunity |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-05-31 : 19:19:06
|
You are using a approach that is obsolite.Use thisImports SystemImports System.DataImports System.Data.OleDb Class Class1 Private Sub Connect(ByVal FileName As String) Dim myConnection As OleDbConnection = New OleDbConnection("File Name = " & FileName ) Try myConnection.Open() If myConnection.State = ConnectionState.Open Then Console.WriteLine("Connection opened successfully!") Else Console.WriteLine("Connection could not be established") End If Catch ex As Exception Console.WriteLine(ex.Message.ToString()) Finally myConnection.Close() End Try End Sub End Class |
 |
|
|
|
|
|