SQL异常未处理(找不到存储过程) [英] Sql exception unhandled(could not find store procedure)

查看:133
本文介绍了SQL异常未处理(找不到存储过程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

这是我执行存储过程的C#代码.

hello friends,

this is my c# code for store procedure executing.

try
          {

              SqlCommand cmd=new SqlCommand("sp_addschool",Dob.con);
              Dob.con.Open();
             /// cmd.Connection=Dob.con;
              cmd.CommandType=CommandType.StoredProcedure;
             // cmd.CommandText="dbo.sp_addschool";
              cmd.Parameters.Add(new SqlParameter("@schoolid",fr2.SCHOOLID));
              cmd.Parameters.Add(new SqlParameter("@scoolname",fr2.SCHOOLNAME));
              cmd.Parameters.Add(new SqlParameter  ("createddatetime",fr2.CREATEDDATEANDTIME));
              int affectedrows=cmd.ExecuteNonQuery();
              return affectedrows;
          }
           catch(Exception ex)
          {
               throw ex;
           }
           finally
          {
              if(Dob.con!=null)
              {
                  Dob.close();
              }
          }


这是我的存储过程


And this is my Store procedure

ceate procedure sp_addschool(@schoolid int,@schoolname varchar(100),@createddateandtime datetime)
as
begin
insert into School (School_id,School_name,Created_date_time)values(@schoolid,@schoolname,@createddateandtime)
end



我的连接字符串是



My connection string is

<connectionstrings>
		<add name="Connectionstring1" providername="System.Data.SqlClient">
			  connectionString="Data Source=USER-PC\MSSQLSERVER11;Initial Catalog=bas;Integrated Security=True" />
	</add></connectionstrings>


如下调用连接字符串


calling connectionstring as below

public static string constring =System.Configuration.ConfigurationManager.ConnectionStrings["Connectionstring1"].ConnectionString;
        //   public static ConnectionStringSettings consetting = ConfigurationManager.ConnectionStrings["ConnectionString"];
        // public static string constring = consetting.ConnectionString;
        public static SqlConnection con = new SqlConnection(constring);

        //public DOB1()
        //{
        //}
        public static void open()
        {
            if (con.State == System.Data.ConnectionState.Closed)
            {
                con.Open();
            }
        }
        public static void close()
        {
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
        }
    }


我的coding.excetion中出现什么问题,因为找不到存储过程"sp_addschool"
请帮助我


what is the problem in my coding.excetion occurs as could not find store procedrue"sp_addschool"
please help me

推荐答案

CREATE SP创建中的关键字不正确. SP可能尚未创建,并且在您尝试访问它时将找不到它.
CREATE KEYWORD in SP creation is incorrect. SP might not have created and when you try to access it, it will not be found.


这篇关于SQL异常未处理(找不到存储过程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆