Using Visual studio 2017, I tried to write and verify programming with a simple WebFormApplication to verify connectivity with SQL Server, but the test connection and build went well, but when I actually moved it, I got an "unhandled exception."What is the cause?
using System;
using System.Collections.General;
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 TestConnection 2
{
public partial class Form 1:Form
{
public Form 1()
{
InitializeComponent();
}
public string contring="Server=localhost\\SQLEXPRESS; Database=master; Trusted_Connection=True";
private void button1_Click(object sender, EventArgse)
{
SqlConnection con=new SqlConnection(conString);
con.Open();
if(con.State==System.Data.ConnectionState.Open)
{
string q = "insert into User(id, name) values('+textID.Text.ToString()+"', '+textName.Text.ToString()+");
SqlCommand cmd = new SqlCommand(q,con);
cmd.ExecuteNonQuery();
MessageBox.Show("Connection made Successful.");
}
}
}
}
There was no problem using the same code.Is it a SQLEXPRESS issue?The User table is not known if it is in the master database.
© 2025 OneMinuteCode. All rights reserved.