Asp.net 类型为';System.Data.SqlClient.SqlException';发生在System.Data.dll中,但未在用户代码错误中处理?

Asp.net 类型为';System.Data.SqlClient.SqlException';发生在System.Data.dll中,但未在用户代码错误中处理?,asp.net,vb.net,Asp.net,Vb.net,尝试将以下信息插入数据库时,我得到“System.Data.SqlClient.SqlException”类型的异常发生在System.Data.dll中,但未在用户代码错误中处理?”错误 我的代码如下: Imports System.Data.SqlClient Partial Class SecurePages_AddBackup Inherits System.Web.UI.Page Protected Sub Button1_Click(sender As Object, e As E

尝试将以下信息插入数据库时,我得到“System.Data.SqlClient.SqlException”类型的异常发生在System.Data.dll中,但未在用户代码错误中处理?”错误

我的代码如下:

Imports System.Data.SqlClient
Partial Class SecurePages_AddBackup
Inherits System.Web.UI.Page

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim conn As SqlConnection
    Dim cmd As SqlCommand

    Dim customer As Integer
    Dim backupDate As String
    Dim Server As Integer
    Dim Status As String
    Dim Product As Integer
    Dim Details As String

    customer = ddlCustomer.SelectedValue
    backupDate = clDate.SelectedDate
    Server = DDLserver.SelectedValue
    Status = DDLStatus.Text
    Product = DDLproduct.SelectedValue
    Details = txtDetails.Text




    Dim cmdstring As String = "INSERT INTO Backup(CustomerID, Date, ServerID, Status, ProductID, Details) Values (@Customer, @BackupDate, @Server, @Status, @Product, @Details)"

    conn = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Backups.mdf;Integrated Security=True")
    cmd = New SqlCommand(cmdstring, conn)

    cmd.Parameters.AddWithValue("@Customer", customer)
    cmd.Parameters.AddWithValue("@BackupDate", backupDate)
    cmd.Parameters.AddWithValue("@Server", Server)
    cmd.Parameters.AddWithValue("@Status", Status)
    cmd.Parameters.AddWithValue("@Product", Product)
    cmd.Parameters.AddWithValue("@Details", Details)
    conn.Open()

    cmd.ExecuteNonQuery()




    conn.Close()

    lblStatus.Text = "Backup added to the database!"
End Sub
End Class
我不确定哪里出了问题。

备份是SQL Server中的一项重要功能


请尝试
插入[备份]

您在项目、SQL Express或SQL Server中使用的是.MDF文件吗?如果您使用的是express或sql server。。。下面是一个可能对您有所帮助的连接字符串格式。数据源=YOUR-SERVER-NAME\SQLEXPRESS;初始目录=YOUR-DB-NAME;“integratedsecurity=True providerName=“System.Data.SqlClient”我在项目中使用了一个MDF文件。它在代码行中与
cmd.ExecuteNonQuery()断开
当程序崩溃时,我在浏览器中得到以下错误:关键字“Backup”附近语法不正确。但仍不确定错误代码在关键字“Backup”附近的位置?检查异常及其内部异常,它将包含实际的异常消息。