[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Returning Stored procedure from SQL via ODBC

Posted on 2013-05-24
1
Medium Priority
?
314 Views
Last Modified: 2013-06-18
Hello,

I have a very big application here that connects to a mySQL database. For each stored procedure in the server, there is a function or sub in the application. The problem is that I needed to migrate this database to a SQL Server, so all the routines that were made for mySQL need to be adapted...

The app has a function to "ExecuteReader" and a "ExecuteCommand" to read tables and send commands with no return.

The ExecuteReader function is like this:
    Function ExecuteReader(ByVal SQLString As String, Optional ByVal Parameters As List(Of OdbcParameter) = Nothing) As DataTable

        SyncLock GlobalCommandBridge

            'Function that executes a command bringing back results, usually used for selects. It returns all results as a Datatable.
            Dim Result As DataTable = New DataTable

            'bridgeCommand = New OdbcCommand("USE " & Database & ";", bridgeConnection)

            Try
                bridgeCommand.Parameters.Clear()
                'If Not ConnectionState = Data.ConnectionState.Open Then OpenConnection()
                'bridgeCommand.ExecuteNonQuery()

                'Set Parameters if there are any
                If Not Parameters Is Nothing Then
                    For Each Parameter As OdbcParameter In Parameters
                        bridgeCommand.Parameters.Add(Parameter)
                    Next
                End If

                If bridgeConnection.State = ConnectionState.Open Then

                    'Executes the command and gather the result back to the Result Datatable object.
                    bridgeCommand.CommandText = Replace(SQLString, "\", "\\")
                    'Application.DoEvents()
                    Result.Load(bridgeCommand.ExecuteReader)
                    Return Result

                Else

                    'If the connection couldn't be opened, returns nothing.
                    Return Nothing

                End If

            Catch ex As Exception

                MsgBox(ex.Message)
                Return Nothing

            End Try

        End SyncLock

    End Function

Open in new window



And an example of stored procedure call from app is this:
    Public Function prcUsrReturnSystem(ByVal id_System As Integer) As DataTable

        'Returns user system details based on it's ID.
        Dim Parameters As New List(Of OdbcParameter)
        Dim AddingParameter As OdbcParameter
        AddingParameter = New OdbcParameter("@id_System", OdbcType.Int, Len(id_System), "id_System")
        AddingParameter.Value = id_System
        Parameters.Add(AddingParameter)

        Return ExecuteReader("exec dbMe..prcUsrReturnSystem (?);", Parameters)

    End Function

Open in new window



Since there are tons of functions like this, I rather adapt the "ExecuteReader" function to work without changing them... One thing I noticed is that parameters in SQL Server have an "@" in front of them... I was trying to make it work but got the error:

ERROR [42000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '@P1

Open in new window


Any ideas??


thanks a lot
0
Comment
Question by:toddinho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 2000 total points
ID: 39195462
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question