Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using ODBCConnection and trying to get back InfoMessage .. the sql anywhere driver is odbc11.dll. I am not getting the InfoMessage even raised!! Can someone please help! The server is Sybase IQ

C#
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);
        }
    }
}
Posted
Updated 17-May-12 4:00am
v3

Few things you could try:
- define the message as TYPE WARNING
- Use ExecuteNonQuery instead of ExecuteReader
 
Share this answer
 
Comments
debdeep Bhattacharyya 17-May-12 9:55am    
Cannot Change the message its in a lot of stored procs ...
I cant execute non query as I have to return tables from stored procs ...
By the way my server is Sybase IQ
Wendelius 17-May-12 10:00am    
Ok, if I've understood correctly, if the message statement is used inside a procedure then the message must be associated with a connection using the connection ID
debdeep Bhattacharyya 17-May-12 10:05am    
How do I get the connection ID? I know C# not very good with SQL. Can you give an example with TSQL code please!
Wendelius 17-May-12 10:14am    
It's been ages since I've used Sybase, but if I'm not wrong, connection_id() should return the connection id. See also MESSAGE statement[^]
debdeep Bhattacharyya 17-May-12 10:22am    
Is there any other way than changing the text inside the .sql file, as my tool is ideally running it against a DB. I dont want to modify the text ..
I am using AsaConnection instead of OdbcConnection. It is provided by Sybase SQL Anywhere inside ianywhere.data.asaclient.dll .. Now I get back the InfoMessage!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900