【发布时间】:2023-03-11 10:10:01
【问题描述】:
我收到一个错误,这是我的代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace dbgen
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using(SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = "Server=DESKTOP-7AN9GF5;Database=Velocity;Trusted_Connection=true";
// using the code here...
conn.ConnectionString = "connection_string";
conn.Open();
using (SqlConnection connection = new SqlConnection(
"Integrated Security=SSPI;Initial Catalog=Northwind"))
{
connection.Open();
// Pool A is created.
}
using (SqlConnection connection = new SqlConnection(
"Integrated Security=SSPI;Initial Catalog=pubs"))
{
connection.Open();
// Pool B is created because the connection strings differ.
}
using (SqlConnection connection = new SqlConnection(
"Integrated Security=SSPI;Initial Catalog=Northwind"))
{
connection.Open();
// The connection string matches pool A.
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainform());
}
}
}
我正在使用 Visual Studio 2013 将数据库连接到 SQL Server Express 上的 Velocity [数据库名称]。这是错误的屏幕截图。
感谢您的帮助。
【问题讨论】:
-
异常的有趣部分是您在单击“查看详细信息”时看到的内容。 ArgumentException(通常)发生在由于将错误数据作为参数传入而发生某些事情时。但是,交集的东西通常在 Message 属性中(如果它不为 null,则在 InnerException 属性中)。通过检查 $exception 伪变量,您可以在 Watch 窗口中查看当前异常。哦,您可以将异常详细信息复制/粘贴为文本。
-
异常图像没有用。此外,它们是不赞成投票的一个很好的理由(请参阅this)。所以,请用文本替换它。
标签: c# sql-server database-connection