此异常最初是在此调用堆栈中引发的:
[外部代码]
Demo.Form1.Form1_Load(object, System.EventArgs) - 位于 Form1.cs
[外部代码]
小禾斗 发表于2021-02-08 15:26
没见到过这个错误,把代码贴出来
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//创建数据库连接字符串
string SqlStr = "Server=DESKTOP-NNR6627;User Id=DESKTOP-NNR6627\\24288;Pwd=;DataBase=db_ExamOnline";
SqlConnection con = new SqlConnection(SqlStr); //创建数据库连接对象
con.Open(); //打开数据库连接
if (con.State == ConnectionState.Open) //判断连接是否打开
{
label1.Text = "SQL Server数据库连接开启!";
con.Close(); //关闭数据库连接
}
if (con.State == ConnectionState.Closed) //判断连接是否关闭
{
label2.Text = "SQL Server数据库连接关闭!";
}
}
}
}