我正在尝试使用VB.NET 2005在本地连接到SQL Server Express.我直接从app.config文件中提取了我的连接字符串.当我运行时,我得到NO错误并且连接状态返回打开,但是命令没有被处理. Imports System.D
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你是在虚拟机内运行吗?
我在Snow Leopard上运行,不时从我的mac访问VS2010.我在VM上遇到了类似的问题但是在使用相同的代码时,它运行得很好.
我不确定这是否是问题,但解决方案是在基于Windows的PC上试用它.如果它有效,那么至少你知道它与虚拟机相关.