C# 使用SQL Conn的SQL连接

C# 使用SQL Conn的SQL连接,c#,sql,C#,Sql,您好,连接字符串有问题。正在尝试调用C#中的存储过程。。。这是我的密码 SqlConnection conn = new SqlConnection("Hunt_Lisa"); SqlCommand command = new SqlCommand("blkFinance_noheader", conn); command.CommandType = CommandType.StoredProcedure;

您好,连接字符串有问题。正在尝试调用C#中的存储过程。。。这是我的密码

            SqlConnection conn = new SqlConnection("Hunt_Lisa");
            SqlCommand command = new SqlCommand("blkFinance_noheader", conn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@Path", fn));
            command.ExecuteNonQuery();

我提前感谢您的帮助…

这是我的脚本修订版。。。只是想分享一下

using (SqlCommand cmd = new SqlCommand())
            {

                cmd.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Hunt_Lisa"].ConnectionString);
                cmd.CommandText = "blkFinance_noheader";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Path", SqlDbType.Text).Value = fn;
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();

            }

可能是谷歌搜索的重复,这个错误导致了另外3个SO的标题完全相同。其中一个肯定是您的答案。请查看此处以确保正确格式化连接字符串,因为您在尝试执行查询时也没有显示实际连接字符串的外观。请使用(){}2 try{}catch{}