I am trying to connect to SQL Server Express locally using VB.NET 2005. I pulled my connection string directly from the app.config file. When I run, I get NO errors and the connection states returns open, however the commands are not being processed.
Imports System.Data
Imports System.Data.SqlClient
Public Class frmAddMovie
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim conString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True;User Instance=True;"
Dim con As New SqlConnection(conString)
Dim cmd As New SqlCommand("Insert Into tblMovies(fldTitle, fldDirector, fldRating)Values('Solar Babies', 'PG', 'Rick Flair')", con)
Using con
con.Open()
cmd.ExecuteNonQuery()
End Using
If MessageBox.Show("Movie Added") = Windows.Forms.DialogResult.OK Then
Me.Close()
End If
End Sub
End Class
Are you running this inside of a virtual machine?
I run on Snow Leopard and have to access VS2010 from time to time from my mac. I have had similar issues on a VM but when using the same code otherwise it runs perfectly.
I am not exactly sure if that is the issue, but the solution is to try it on a windows-based PC. If it works, then at least you know it is Virtual Machine-related.