Thursday, March 8, 2012

Could not find stored procedure GetActivePoll?

can anyone please help me with my poll application? whenever i run it, i will comes out with this error "Could not find stored procedure 'GetActivePoll'". i've got stored procedure in my database with the name GetActivePoll', how come it cannot find the stored procedured? below are some images and codes i've attached with.

1<%@. Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="poll.aspx.vb"Inherits="Polls_poll" title="Fanzine if Liverpool FC" %>2<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">3<div style="text-align: left">4 <span style="font-size: 30px; color: #3333ff; font-family: Verdana"><strong><span5 style="color: #000000">Please take a vote...</span><br />6 </strong></span>7 </div>8 <div style="text-align: left">9 <br />10 <table width="100%" align="center">11 <tr>12 <td style="width: 100px; border-top: thin solid; height: 20px;">13 <asp:Label ID="lblPollQuestion" runat="server" Font-Bold="True" Font-Names="Verdana"14 Font-Size="10pt" Text="Poll Question" Width="500px"></asp:Label></td>15 </tr>16 <tr>17 <td style="width: 100px">18 <asp:RadioButtonList ID="rdoPollOptionList" runat="server" Font-Names="Verdana" Font-Size="9pt" Width="500px" DataSourceID="SqlDataSource1" DataTextField="PK_PollId" DataValueField="PK_PollId">19 </asp:RadioButtonList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Poll.mdf;Integrated Security=True;User Instance=True"20 ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Polls]"></asp:SqlDataSource>21 </td>22 </tr>23 <tr>24 <td style="width: 100px; text-align: left">25 <asp:Button ID="btnVote" runat="server" Text="Vote" Width="71px" BackColor="Silver" BorderColor="Silver" BorderStyle="Solid" Font-Bold="True" ForeColor="White" /><br />26 <br />27 <asp:Label ID="lblError" runat="server" Font-Names="Verdana" Font-Size="Smaller"28 ForeColor="Red" Text="You cannot vote more than once..." Visible="False" Width="500px"></asp:Label></td>29 </tr>30 </table>31 </div>32</asp:Content>33
1Imports System.Data2Imports System.Data.SqlClient3PartialClass Polls_poll4Inherits System.Web.UI.Page5Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load6If Not IsPostBackThen7 DisplayPoll()8End If9 End Sub10 Private Sub DisplayPoll()11Try12 Dim dsAs DataSet = getActivePoll()1314 lblPollQuestion.Text = ds.Tables(0).Rows(0)("Question")1516Dim iAs Integer = 017For Each drAs DataRowIn ds.Tables(1).Rows18 rdoPollOptionList.Items.Add(dr("Answer"))19 rdoPollOptionList.Items(i).Value = dr("PK_OptionId")20 rdoPollOptionList.SelectedIndex = 02122 i = i + 123Next24 Catch exAs Exception25Throw ex26End Try27 End Sub28 Private Function getActivePoll()As DataSet29Dim strConnStringAs String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()30Dim sqlConnAs New SqlConnection(strConnString)3132 sqlConn.Open()33Dim sqlCmdAs New SqlCommand()3435 sqlCmd.CommandText ="GetActivePoll"36 sqlCmd.CommandType = Data.CommandType.StoredProcedure37 sqlCmd.Connection = sqlConn3839Dim dsAs New DataSet40Dim daAs New SqlDataAdapter(sqlCmd)4142 da.Fill(ds)4344 sqlConn.Close()4546Return ds47End Function48 Protected Sub btnVote_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnVote.Click49If Response.Cookies("Voted")Is Nothing Then50 Response.Cookies("Voted").Value ="Voted"51 Response.Cookies("Voted").Expires = DateTime.Now.AddDays(1)5253 lblError.Visible =False5455 RecordVote()56Else57 lblError.Visible =True58 End If59 End Sub60 Private Sub RecordVote()61Dim strConnStringAs String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()62Dim sqlConnAs New SqlConnection(strConnString)6364 sqlConn.Open()65Dim sqlCmdAs New SqlCommand()6667 sqlCmd.CommandText ="IncrementVote"68 sqlCmd.CommandType = Data.CommandType.StoredProcedure69 sqlCmd.Connection = sqlConn7071Dim sqlParamQuestionAs New SqlParameter("@.i_OptionId", Data.SqlDbType.Int)7273 sqlParamQuestion.Value = rdoPollOptionList.SelectedValue7475 sqlCmd.Parameters.Add(sqlParamQuestion)7677 sqlCmd.ExecuteNonQuery()7879 sqlConn.Close()80End Sub81End Class
error found


If you change line 35 to

 sqlCmd.CommandText ="[GetActivePoll]"

does it work?

|||

Are you looking in the right DB? Its a good idea to drop and recreate the proc and qualify with the owner as

CREATE PROCdbo.GetAcviePoll

Lot of times when developoers create the objects, if they are not created with the qualifier they are created under the developers credentials.

No comments:

Post a Comment