Ajax slideshow error: The server method 'GetSlides' failed with the following error: System.Data.SqlClient.SqlException--incorrect syntax near ')'.

Hello there,

I am new to asp.net and ajax. I have been working non-stop trying to figure out what leads to the following error on my slideshow page:

The server method 'GetSlides' failed with the following error: System.Data.SqlClient.SqlException--incorrect syntax near ')'.

 

My code is as follows:

Imports System.Data

Imports System.Data.Sql

Imports System.Data.SqlClient

Partial Class ProjectInherits System.Web.UI.Page

<System.Web.Services.WebMethod()> _

<System.Web.Script.Services.ScriptMethod()> _

Public Shared Function GetSlides() As AjaxControlToolkit.Slide()

Dim cnn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

Dim querystr As String = System.Web.HttpContext.Current.Request.QueryString("ProjID")

Dim cmd As New SqlCommand("SELECT * from photoTable Where([ProjID] = " & querystr & ")", cnn)

Dim dr As SqlDataReader

Dim sqlDataAdapter As SqlDataAdapter

Dim dataSet As DataSet

'instantiate SqlAdapter and DataSet

sqlDataAdapter = New SqlDataAdapter(cmd) dataSet = New DataSet()

'populate the DataSet

sqlDataAdapter.Fill(dataSet, "Photo")

Dim count As Integer = dataSet.Tables("Photo").Rows.Count() - 1

Dim scriptstring(count) As AjaxControlToolkit.Slide

Try

cnn.Open()

dr = cmd.ExecuteReader()

Dim i As Integer = 0

Do While dr.Read()

scriptstring(i) = New AjaxControlToolkit.Slide("ProjPhotos/" & dr("PjtPhotoLarge"), "", "")

i = i + 1

Loop

Catch e As Exception

Finally

If Not cmd Is Nothing Then

cmd.Dispose()

End If

If Not cnn Is Nothing Then

cnn.Close()

cnn.Dispose()

End If

End Try

Return scriptstring End Function

End Class

 

However, I notice that if I replace this line of code:

        Dim cmd As New SqlCommand("SELECT * from photoTable Where([ProjID] = " & querystr & ")", cnn)

 

with

        Dim cmd As New SqlCommand("SELECT * from photoTable Where([ProjID] = 1)", cnn), then it works...

 

Any help is really appreciated.

 

Thanks.

0
tanhc
8/28/2007 8:07:44 AM
asp.net.ajax_control_toolkit 17816 articles. 1 followers. Follow

7 Replies
1222 Views

Similar Articles

[PageSpeed] 14

 Hi,

Please note the the URL for this GetSlides method isn't the one you see in the address bar of your browser, so it's likely that querystring ProjID doesn't exist. Actually, a different thread is used to server this request.

I suggest not using querystring but contextKey to pass the projID into it. 

For instance:

<ajaxToolkit:SlideShowExtender ID="slideshowextend1" runat="server"
                TargetControlID="Image1" BehaviorID="ss1" ContextKey="projID to be passed // it can also be assigned in code behind too"  ........ />

Public Shared Function GetSlides(byref contextKey as string) As AjaxControlToolkit.Slide

     Dim querystr As String = contextKey  ........................

 

 Hope this helps.

0
Raymond
8/31/2007 3:40:51 AM

Hello Raymond,

Thank you very much for your reply. However, I am not really sure how to implement your suggestion as I am not that familiar with contextkey. Would you mind to elaborate your suggestion in more detail or have you come across any example on using similar method that I intend to use?

Many thanks.

0
tanhc
9/1/2007 8:30:47 AM

You can set the contextKey in Page_Load method.

function Page_Load()

    slideshowextend1.ContextKey = Request.QueryString["projid"]

 

Then get this value via parameter contextkey in GetSlides method

Public Shared Function GetSlides(byref contextKey as string) As AjaxControlToolkit.Slide

     Dim querystr As String = contextKey  ........................

 

0
Raymond
9/3/2007 1:55:47 AM

Thanks for the immediate reply Raymond. Really appreciated.

I tried to use the contextkey as demonstrated, but I think that I might have overlooked something because now I am seeing this new error:

The server method "GetSlides" failed with the following error: System.InValidOperationException--cannot convert object of type ‘system.string' to ‘system.string&'

My codes are as follows:

 

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Copy of Project.aspx.vb" Inherits="Project" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContentHolder" Runat="Server">

<form id="form1">
        <div align="center">        
            <asp:Image ID="Image1" runat="server" ImageUrl="" Width="300px" />
            <br />
            <br />
            <asp:Button ID="prevButton" runat="server" Text="Previous" />
            <asp:Button ID="playButton" runat="server" Text="Play" />
            <asp:Button ID="nextButton" runat="server" Text="Next" />
            <ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" TargetControlID="Image1" runat="server" AutoPlay="true" NextButtonID="nextButton" PlayButtonID="playButton" PlayButtonText="Play" PreviousButtonID="prevButton" StopButtonText="Stop"  ImageDescriptionLabelID="Label1" Loop="true" SlideShowServiceMethod="GetSlides"> </ajaxToolkit:SlideShowExtender> 
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>
        
</form>
</asp:Content>




Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Web.HttpContext


Partial Class Project
    Inherits System.Web.UI.Page

    <System.Web.Services.WebMethod()> _
        <System.Web.Script.Services.ScriptMethod()> _
        Public Shared Function GetSlides(ByRef contextKey As String) As AjaxControlToolkit.Slide()

        Dim cnn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim querystr As String = contextKey
        Dim cmd As New SqlCommand("SELECT * from photoTable Where([ProjID] = " & querystr & ")", cnn)

        Dim dr As SqlDataReader
        Dim sqlDataAdapter As SqlDataAdapter
        Dim dataSet As DataSet

        'instantiate SqlAdapter and DataSet
        sqlDataAdapter = New SqlDataAdapter(cmd)
        dataSet = New DataSet()

        'populate the DataSet
        sqlDataAdapter.Fill(dataSet, "Photo")

        Dim count As Integer = dataSet.Tables("Photo").Rows.Count() - 1

        Dim scriptstring(count) As AjaxControlToolkit.Slide

        Try
            cnn.Open()
            dr = cmd.ExecuteReader()
            Dim i As Integer = 0

            Do While dr.Read()
                scriptstring(i) = New AjaxControlToolkit.Slide("ProjPhotos/" & dr("PjtPhotoLarge"), "", "")
                i = i + 1
            Loop

        Catch e As Exception

        Finally
            If Not cmd Is Nothing Then
                cmd.Dispose()
            End If

            If Not cnn Is Nothing Then
                cnn.Close()
                cnn.Dispose()
            End If
        End Try
        Return scriptstring
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SlideShowExtender1.ContextKey = Request.QueryString("ProjID")
    End Sub
End Class
 

Hope that you can shed some light into my problem. Thank you very much.

0
tanhc
9/3/2007 10:35:33 AM
Sorry, I made a mistake in my previous post. The parameter should be passed by value, not passed by reference. 
Public Shared Function GetSlides(ByVal contextKey As String) As AjaxControlToolkit.Slide()

 

0
Raymond
9/4/2007 1:34:06 AM

Thanks Raymond. It works!

0
tanhc
9/4/2007 6:33:43 AM

I am getting same error with IndexOutOfRange exception. Here is my code:

 

Imports System.Web

Imports System.Web.Services

Imports System.Web.Services.Protocols

Imports System.Web.Script.Services

Imports System.IO

 

 

<WebService(Namespace:="http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<System.Web.Script.Services.ScriptService()> _

    Public Class GetSlides_WebService

    Inherits System.Web.Services.WebService

 

 

    <WebMethod()> _

    <ScriptMethod()> _

    Public Function GetSlides(ByVal contextKey As String) As AjaxControlToolkit.Slide()

        Dim strFileNames() As String = Directory.GetFiles(Server.MapPath("~\General\Images\home\images\"))

        Dim photos() As AjaxControlToolkit.Slide = New AjaxControlToolkit.Slide(strFileNames.Length - 1) {}

        If strFileNames.Length > 0 Then

            For i As Integer = 0 To strFileNames.Length - 1

                Dim strFile() As String = strFileNames(i).Split("\"c)

                photos(i) = New AjaxControlToolkit.Slide("..\General\Images\home\images\" & strFile(strFileNames.Length - 1), "", "")

            Next

        End If

        Return photos

    End Function

 

End Class

 

It works in DEV but not in PRD.


 


Thanks
I love computers because: MY WISH IS THEIR COMMAND :)

<Website>
<Gadget>
0
yaip
10/22/2007 9:25:33 PM
Reply:

Similar Artilces:

The server method 'SaveData' failed with the following error: System.Data.NoNullAllowedException: Column 'COLUMN' does not allow nulls.
Hello all, I am dabbling in client side atlas at the moment, and I'm attempting to use a strongly typed dataset with a dataservice to update and insert items into it.  Editing is working flawlessly.  I made a button that can save the data if it's changed.  My problem is in the insert.  I've been using the 1_ListOfTask.aspx example as my starting point, where I created the following:  function onCreateCourse()    {        // Get each control        var newSID = S...

The server method 'GetSlides....' failed with the following error: Could not create type 'Slideservice1'
I' ve created app in which I implemented SlideShowExtender. Firstable,   I created SlideShowExtender which retrieves all images from db table and solution worked well - both locally and on remote server. Now, I have SlideShowExtender which retrieves images depending on user selection from dropdownlist. Locally, it works great, but when I attempt to start the slide show on internet, I'm getting this error: The server method 'GetSlides....' failed with the following error: the error occured during the parsing of a resource required to service this request. &nbs...

server error in '/' Application Incorrect syntax near ','.
This code used to work now I get an error(error follows code)  can anyone tell me where I went wrong?[vbcode]i = 0            For i = 0 To 7                If requests(i) <> "" Then                    request = requests(i)                    Dim sql1 As String =...

Error:System.Data.SqlClient.SqlException: Line 1:Incorrect syntax near 'oximetry'.
This is the first time I have seen this kind of error message for running a VS 2005/ASP.net 2.0website.  What does "Line 1" mean?  I can not understand which line of ASP.net code is wrong.ASP Source code or ASP.vb code?  I have a database column named [PVS DLCo oximetry].  Something wrong with this column name?  The webpagedisplayed the column name as 3 lines of PVS, DLCo, oximetry.  After clicking the Edit button and changingdata, clicking the Update button showed the error message. Where should I start to look for error code?   <asp:SqlD...

Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'UpdatePassword' failed with the following error: System.InvalidOperationException-- Cannot convert null to a valu
I am using this code to update password on a click event of a html button using AJAX and I am getting an error If I try to debug my Javascript. Error: Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'UpdatePassword' failed with the following error: System.InvalidOperationException-- Cannot convert null to a value type. OR  If I dont debug Javascript and click the button, then it says that 'Dont but with error' on the bottom of the page and It does not update the password in the database. ASP.Net Code: <asp:ScriptManager I...

The server method 'UnlockRecord' failed with the following error: '
 I've spent the past 20 minutes scouring Google on this one, and I've got nothing. I have a JavaScript snippet in my page:  <script type="text/javascript"> window.onbeforeunload=UnloadMe; function UnloadMe() { if(document.getElementById('ctl00_ContentPlaceHolder1_lblLocked').innerHTML != '') ICE.Activations_Services.UnlockRecord(document.getElementById('ctl00_ContentPlaceHolder1_txtInstallCardNumber').value, document.getElementById('ctl00_ContentPlaceHolder1_lblLocked').innerHTML.substring(18,...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'TypeConverter' is unable to convert 'System.Data.SqlClient.SqlConnection' to 'System.Data.SqlClient.SqlConnection'.
Hey, I was hoping someone could shed some light on this error for me. I am using the TypeConverter in the System.ComponentsModel Namespace, and when I attempt to take an object, which in this case is a SQLConnection, and perform a TypeConvert (code example below) I get the following error: Error: ---------------------------------------------------------------------------- 'TypeConverter' is unable to convert 'System.Data.SqlClient.SqlConnection' to 'System.Data.SqlClient.SqlConnection'. ---------------------------------------------------------------------------- ...

wegconfig connectionstring ADODB System.Data.Odbc error is [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'TSQL'
    <add name="MYADODBCUSTOMERCONNECTIONSTRING" connectionString="Driver={SQL Server};Server=xxx.xxx.xxx.xxx;Database=myDbname;Uid=xxxxx;Pwd=xxxxx" providerName="System.Data.Odbc" />   [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'TSQL'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: [Micros...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

Error 2 'Text' is not a member of 'System.Data.SqlClient.SqlParameter'
Error    2    'Text' is not a member of 'System.Data.SqlClient.SqlParameter'.  I think this error has something to do with the lack of an Import command, anyone point me in the right direction?  sorry, I've decided to upload all the code of default.aspx.vb...I'm trying to make a mailing list sign up. So member can add their name and email for a monthly newsletter. I'm getting three errors, the one posted above on each of the three text boxes. what do I do? Thanks very much  Partial Class _Default    Inherits System.Web.U...

Error: foreach statement cannot operate on variables of type 'System.Data.DataSet' because 'System.Data.DataSet' does not contain a definition for 'GetEnumerator', or it is inaccessible
I am getting error on this line DataSet dsdata=new DataSet(); SQL="Seelct * from tablename"; //dsdata contains result of the above query foreach(DataRow dr in dsdata) //This line gives error Error: foreach statement cannot operate on variables of type 'System.Data.DataSet' because 'System.Data.DataSet' does not contain a definition for 'GetEnumerator', or it is inaccessible DataSet dsdata=new DataSet(); SQL="Select * from tablename"; //dsdata contains result of the above query foreach(DataRow dr in dsdata.Tables[0].Rows) //This ...

Error 39 'System.Data.DataRow' does not contain a definition for 'Item'
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { categoryID = ds.Tables[0].Rows[i].Item["categoryID"]; name = ds.Tables[0].Rows[i].Item["name"]; string catID = Convert.ToString(categoryID); ///Change made by me ddlCategory.Items.Add(new ListItem(name, catID)); qry = "Select count(categoryID) from categories where active = 'True' AND parentID=" + categoryID + ""; countCategories = objDB.getScalar(qry);       i get this errorIf the going seems easy, You are going DownHill... I've got the solution what you have to ...

Server Error in '/Webapp' Application. Could not load file or assembly 'System.Data' or one of its dependencies. An attempt was made to load a program with an incorrect format.
 10 minutes ago, my web app worked fine.  Now it appears broken and I hadn't touched the web.config file.  Anyone know what might be going on here?  I checked my web server's .NET folder (C:\WINDOWS\microsoft.net\Framework64\v2.0.50727) and there is indeed a system.data.dll file...  Could not load file or assembly 'System.Data' or one of its dependencies. An attempt was made to load a program with an incorrect format. Description: An unhandled exception occurred during the execution of the current web request. Plea...

Web resources about - Ajax slideshow error: The server method 'GetSlides' failed with the following error: System.Data.SqlClient.SqlException--incorrect syntax near ')'. - asp.net.ajax_control_toolkit

The Case of an Obscure Injection
During a recent application penetration test, I came across what proved to be an interesting SQL Injection (SQLi) vulnerability. This case of ...


Resources last updated: 12/6/2015 12:50:02 AM