找不到存储过程- SQLDataSource

本文关键字:SQLDataSource 存储过程 找不到 | 更新日期: 2023-09-27 17:51:08

其他类似的问题并没有真正与我的问题相关,所以我正在制作一个新的…

<asp:SqlDataSource ID="SqlDataSource2"  runat="server" ConnectionString="<%$ ConnectionStrings:CatalogosConnectionString %>" 
                          InsertCommand="dbo.GRM_Novo_Catalogo" InsertCommandType="StoredProcedure"> 
    <InsertParameters>
        <asp:Parameter Name="Nome" Type="String" />
        <asp:Parameter Name="NomeAbreviado" Type="String" />
        <asp:Parameter Name="Estado" Type="Int64" />
        <asp:Parameter Name="OrganismoID" Type="Int64" />
        <asp:Parameter Name="TipoCatalogoID" Type="Int64" />
    </InsertParameters>
</asp:SqlDataSource>

后台代码:

protected void Button2_Click(object sender, EventArgs e)
{
    SqlDataSource2.InsertParameters["Nome"].DefaultValue = TextBox13.Text;
    SqlDataSource2.InsertParameters["NomeAbreviado"].DefaultValue = TextBox14.Text;
    SqlDataSource2.InsertParameters["Estado"].DefaultValue = TextBox15.Text;
    SqlDataSource2.InsertParameters["OrganismoID"].DefaultValue = TextBox16.Text;
    SqlDataSource2.InsertParameters["TipoCatalogoID"].DefaultValue = TextBox17.Text;
    SqlDataSource2.Insert();
}

所以我想要的是,当用户单击Button2时,它从数据库中运行该存储过程,但是在测试时,它会弹出一个错误消息,说它找不到存储过程。

我在另一个SQLDataSource上使用相同的连接字符串并且它工作(这也使用了与上面代码中相同位置的存储过程)

堆栈跟踪:

Message:
DotNetNuke.Services.Exceptions.PageLoadException: Could not find stored procedure 'dbo.GRM_Novo_Catalogo'. ---> System.Data.SqlClient.SqlException: Could not find stored procedure 'dbo.GRM_Novo_Catalogo'.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation)
   at System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values)
   at System.Web.UI.WebControls.SqlDataSource.Insert()
   at EmptyWebsite3.Modules.DNNModule1.Edit.Button2_Click(Object sender, EventArgs e) in c:'Users'me'Documents'My Web Sites'EmptySite3'DesktopModules'DNNModule1'Edit.ascx.cs:line 79
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   --- End of inner exception stack trace ---

找不到存储过程- SQLDataSource

我意识到这是抓稻草-您是否尝试过不同的语法来调用您的SP?

下面是我在DataAccess类中使用的一个典型调用:
public int setUserTimescale(DataObjects.UserDetails myUserDetails)
{
    int ReturnValue = -1;
    SqlConnection myConnection = new SqlConnection(connectionString);
    SqlCommand myCommand = myConnection.CreateCommand();
    myCommand.CommandText = "User_Timescale_Up";
    myCommand.CommandTimeout = 120;
    myCommand.Connection = myConnection;
    myCommand.CommandType = CommandType.StoredProcedure;
    myCommand.Parameters.Add("UserID", SqlDbType.Int).Value = myUserDetails.UserID;
    myCommand.Parameters.Add("TimescaleID", SqlDbType.Int).Value = myUserDetails.TimescaleID;
    SqlParameter parameterReturnValue = new SqlParameter("@ReturnValue", SqlDbType.Int);
    parameterReturnValue.Direction = ParameterDirection.Output;
    myCommand.Parameters.Add(parameterReturnValue);
    try
    {
        myConnection.Open();
        myCommand.ExecuteNonQuery();
        // Get the return value
        ReturnValue = (int)myCommand.Parameters[2].Value;
    }
    catch (Exception e)
    {
        setDBError(myCommand, e.Message.ToString(), "User_Timescale_Up");
        ReturnValue = -2;
    }
    finally
    {
        myConnection.Close();
    }
    return ReturnValue;
}