StoredProcedure中的错误

时间:2016-12-24 22:46:58

标签: tsql stored-procedures

ALTER PROCEDURE [dbo].[UploadFile] (
@FileName VARCHAR(150),
@FileSize INT,
@FileContentType VARCHAR(200),
@FileExtension VARCHAR(10),
@FileContent VARCHAR(MAX)
)
AS
BEGIN
INSERT INTO FilesData( FileName,FileSize,FileContentType,FileExtension,FileContent ) VALUES
  ( @FileName,@FileSize,@FileContentType,@FileExtension,@FileContent )
END
  

这个SaveFile.cs

    public class SaveFile
{
    public string FileName { set; get; }
    public string FileExtension { set; get; }
    public byte[] FileContent { set; get; }

    public string SaveFileToDB()
    {
        using (SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"D:\\TinyShare\\App_Data\\TinyShareDB.mdf\";Integrated Security=True" + "Initial Catalog=TinyShareDB_log.ldf;Integrated Security=True;Pooling=False"))
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure; 
            cmd.CommandText = "UploadFile";
            cmd.Connection = conn;

            cmd.Parameters.AddWithValue("@FileContent", FileContent);
            cmd.Parameters.AddWithValue("@FileName", FileName);
            cmd.Parameters.AddWithValue("@FileExtension", FileExtension);
            cmd.Parameters.AddWithValue("@FileSize", FileExtension);
            cmd.Parameters.AddWithValue("@FileContentType", FileExtension);


            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                return "File stored Successfully!!!";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }
     }}

Error in alter

1 个答案:

答案 0 :(得分:0)

  1. 使用USE statement指定您的数据库。
  2. 不要使用alter,但更喜欢drop并创建systax。
  3. 在创建之前检查您的对象是否存在。

    use DbName
    go
    if object_id('YourProc') is null drop procedure YourProc
    create YourProc...
    
  4. 如果将鼠标指针移到红色带下划线的文本上方,则会收到详细的错误说明。

    您的ALTER有下划线,因为您的对象可能尚未存在或无法访问此对象,因为您的脚本不知道您的程序在哪里。

相关问题