Wednesday, March 7, 2012

Microsoft.Data.Odbc.OdbcException: ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL S

Hi Everybody,

On localhost this application works fine but when I put on remote server. I am getting following errors. For both localhost and server, I am using same remote sql 2000. I will appreciate any help.

Thanks,

Arif

Server Error in '/' Application.
------------------------

ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ')'.
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: Microsoft.Data.Odbc.OdbcException: ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ')'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[OdbcException: ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ')'.]
Microsoft.Data.Odbc.OdbcConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) +27
Microsoft.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method) +838
Microsoft.Data.Odbc.OdbcCommand.ExecuteNonQuery() +80
Calgary.venues.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Calgary\Site\venues\venues.aspx.vb:32
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731are you using ODBC to connect to sql server ??if so you should be using sqlclient...its much better integrated into .net...

hth|||Hi,

Thanks for reply. I am doing some maintaince on some existing code. Somebody else wrote the code. Application was runing againt MySQL but I am converting over to SQL 2000.

Thanks,

Arif|||Here are the Code: Its failing on myCommand.ExecuteNonQuery(). It was working fine before. Even now its works fine on my localhost.

Thanks,

Arif

Dim strSQL As String

' strSQL = "SELECT * from tblbands where name = "

' strSQL = "SELECT tblAdminUsers_ID as Expr1, RealName as Expr2 From tblAdminUsers order by RealName"

Dim sBandName = Request("bandID")

If sBandName = "09" Then

strSQL = "select name, location, genre from tblbands,tbllocation,tblgenre

WHERE(tblbands.Location_ID = tbllocation.tblLocation_ID)AND tblgenre.tblGenre_ID =

tblbands.Genre_ID and tblbands.isapproved=1 and tblbands.name between '0'

AND '9'ORDER BY name "

End If

If sBandName = "AK" Then

strSQL = "select name, location, genre from tblbands,tbllocation,tblgenre

WHERE(tblbands.Location_ID = tbllocation.tblLocation_ID)AND tblgenre.tblGenre_ID =

tblbands.Genre_ID and tblbands.isapproved=1 and tblbands.name between 'A' AND 'K'

ORDER BY name"

End If

If sBandName = "LZ" Then

strSQL = "select name, location, genre from tblbands,tbllocation,tblgenre

WHERE(tblbands.Location_ID = tbllocation.tblLocation_ID)AND tblgenre.tblGenre_ID =

tblbands.Genre_ID and tblbands.isapproved=1 and tblbands.name between 'L' AND 'Z'

ORDER BY name "

End If

Dim myConnString = ConfigurationSettings.AppSettings("ConnectionString")

Dim myConn As New OdbcConnection(myConnString)

Dim myCommand As New OdbcCommand(strSQL, myConn)

myConn.Open()

myCommand.ExecuteNonQuery()

Dim myReader As OdbcDataReader = myCommand.ExecuteReader()

Repeater1.DataSource = myReader

Repeater1.DataBind()

myReader.Close()

myConn.Close()|||remove tht line...you are already using the execute reader...
comment out this line
myCommand.ExecuteNonQuery()

hth|||Same code was working before. Thanks and let me test again.

best regards,

arif

No comments:

Post a Comment