其他类似的问题并没有真正与我的问题相关,所以我正在制作一个新问题......
<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 ---
答案 0 :(得分:0)
我意识到这是在吸管 - 你有不同的语法来调用你的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;
}