Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

I am using ODBCConnection and trying to get back InfoMessage .. the sql anywhere driver is odbc11.dll. I am not getting the InfoMessage raised, can someone please help?

using System.Data.Odbc;
using System;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            using (OdbcConnection con = new OdbcConnection("DRIVER={SQL Anywhere 11};Commlinks=TCPIP{host=***.net:3053};SERVERNAME=***;DATABASEName=***;UID=dba;PASSWORD=**;Integrated=NO"))
            {
                con.InfoMessage += InfoMessage_Event;
                con.Open();
                using (OdbcCommand com = new OdbcCommand("Message 'asdfasdgdag' to client", con))
                {
                    OdbcDataReader r = com.ExecuteReader();
                }
            }
        }
        private static void InfoMessage_Event(object sender, OdbcInfoMessageEventArgs e)
        {
            Console.WriteLine(e.Message);
        }
    }
}

asked 17 May '12, 09:58

debdeepb34's gravatar image

debdeepb34
15111
accept rate: 0%

edited 17 May '12, 15:45

Calvin%20Allen's gravatar image

Calvin Allen
1.5k232638


You are confusing the SQL MESSAGE statement with InfoMessage evetns.

The InfoMessage event contains an OdbcErrorCollection collection with warnings sent from the data source.

MESSAGE does not generate ODBC warnings. Here is a simple example that illustrates the use of OdbcInfoMessageEventHandler. Start your demo server as follows (using an appropriate path to demo.db):

dbeng11 -n demo11 c:sa11samplesdemo.db

The result of the SQL query is non-deterministic so a warning is returned to your InfoMessage event handler.

    class Program
    {
    static void Main(string[] args)
    {
        using (OdbcConnection con = new OdbcConnection(
                    "DRIVER={SQL Anywhere 11};ServerName=Demo11;UserID=DBA;Password=sql"))
        {
        con.InfoMessage += new OdbcInfoMessageEventHandler(InfoMessage_Event);
        con.Open();
        using (OdbcCommand com = new OdbcCommand("select top 3 * from customers", con))
        {
            OdbcDataReader r = com.ExecuteReader();
        }
        con.Close();
        }
    }
    protected static void InfoMessage_Event(object sender, OdbcInfoMessageEventArgs e)
    {
        Console.WriteLine(e.Message);
    }
    }

permanent link

answered 18 May '12, 14:48

JBSchueler's gravatar image

JBSchueler
3.3k41564
accept rate: 19%

If you were to use the SQL Anywhere .NET Data Provider, you would get the message as it inherently handles the MESSAGE...TO CLIENT.

For ODBC connections, the MESSAGE ... TO CLIENT requires the message callback to be registered by calling SQLSetConnectAttr with the ASA_REGISTER_MESSAGE_CALLBACK parameter. I have done a cursory check and did not find any mechanism to set this attribute in OdbcConnection.

permanent link

answered 17 May '12, 11:08

Chris%20Keating's gravatar image

Chris Keating
7.8k49128
accept rate: 32%

edited 17 May '12, 11:08

Can you please please give me an example c# code to register callback using SQLSetConnectAttribute

(17 May '12, 13:30) debdeepb34

As I indicated, I could not find a mechanism to set this in OdbcConnection. Is is possible to use the SQL Anywhere .NET Data Provider which handles the MESSAGE...TO CLIENT without additional calls.

(18 May '12, 07:36) Chris Keating
1

The callback would require a call into unmanaged code so you won't find any support for SA_REGISTER_MESSAGE_CALLBACK (I believe callbacks are a SQL Anywhere invention - I've haven't seen this in the MS ODBC driver).

(18 May '12, 14:54) JBSchueler
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×41
×39

question asked: 17 May '12, 09:58

question was seen: 4,480 times

last updated: 18 May '12, 14:54