Connecting VB.NET 2005 to SQL Server Express, no errors, but cmds do not start

I am trying to connect to SQL Server Express locally using VB.NET 2005. I pulled the connection string directly from the app.config file. When I start, I get NO errors, and connection states are returned, however the commands are not 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 
+4
source share
2 answers

Are you running this inside a virtual machine?

I run on Snow Leopard and from time to time I access VS2010 from my mac. I had similar problems in a virtual machine, but when using the same code otherwise it works fine.

I'm not quite sure that this is a problem, but the solution is to try it on a Windows PC. If this works, then at least you know that it is connected to the virtual machine.

+1
source

AttachDbFilename = | The DataDirectory is located in the bin / debug folder, and by default yours is called again every time you start the project, so what you inserted will be overwritten.

The solution is simple: 1 - Connect directly to the master data

or

2 - In your project, select Movies.mdf, press F4 Set Copy to display the directory in "Do not copy"

0
source

All Articles