繁体   English   中英

C#未处理的参数异常

[英]C# Unhandled Argument Exception

我收到一个错误,这是我的代码。

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 [数据库名称]。 这是错误的屏幕截图。

错误画面

感谢您的帮助。

您必须为“ conn.ConnectionString”分配正确的连接字符串。 “ connection_string”不是连接字符串,应类似于“ Server = xxx; Database = xxx;”。

您的连接字符串格式错误。 你为什么不使用:

conn.ConnectionString = "Server=DESKTOP-7AN9GF5;Database=Velocity;Trusted_Connection=true";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM