1

I am trying to connect C# to an InterBase Database. I have downloaded and install Devart ODBC Driver for Windows and installed it. I configured the System DSN in control panel and got a Success message when I tested the connection. I generated a connection string during the process of configuring the driver which I am using to establish connection to the InterBase Database. I have managed to connect to the database in C# and also in PHP but if I try to query the database I get an error. If I display the connection information, the database name returns a null and I am suspecting that this is where the problem is but I don't know how to solve it.

Here is a link to my Devart ODBC configuration. My code in C# is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Odbc;
using System.Data.SqlClient;

namespace ConsoleApp2 {
    class Program {
        static void Main(string[] args) {

            string connString = "DRIVER=Devart ODBC Driver for InterBase;Description=testing;Data Source=127.0.0.1;Database=C:\\Program Files\\Embarcadero\\Databases\\TEST.GDB;Port=3051;User ID=sysdba;Password=masterkey";
            OdbcConnection conn = new OdbcConnection(connString);

            try {
                conn.Open();
                Console.WriteLine("Connection Information:\t");
                Console.WriteLine("\nConnection String:\t" +
                                  conn.ConnectionString);
                Console.WriteLine("\nConnection Timeout:\t" +
                                  conn.ConnectionTimeout);
                Console.WriteLine("\nDatabase:\t" +
                                  conn.Database);
                Console.WriteLine("\nDataSource:\t" +
                                  conn.DataSource);
                Console.WriteLine("\nDriver:\t" +
                                  conn.Driver);
                Console.WriteLine("\nServerVersion:\t" +
                                  conn.ServerVersion);
            }
            catch (OdbcException ex){
                Console.WriteLine(ex);
            }

        Console.ReadLine();
        }
}
}

The above code is giving me this output.

If I try to do a SELECT query on my 'USER' table in the database this is the error i get:

USERn unknown - line 1, char 15(0x80131937): ERROR [HY000] [Devart][ODBC][InterBase]Dynamic SQL Error at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader) at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Odbc.OdbcCommand.ExecuteReader() at ConsoleApp2.Program.Main(String[] args) in D:\C#\ConsoleApp2\ConsoleApp2\Program.cs:line 38

But if I enter a table name that does not exist in the database e.g. USR this is what i get:

USRle unknowne = -204Exception (0x80131937): ERROR [HY000] [Devart][ODBC][InterBase]Dynamic SQL Error at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader) at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Odbc.OdbcCommand.ExecuteReader() at ConsoleApp2.Program.Main(String[] args) in D:\C#\ConsoleApp2\ConsoleApp2\Program.cs:line 38

mjwills
  • 23,389
  • 6
  • 40
  • 63
tck
  • 61
  • 5
  • show us the `SELECT query on my 'USER' table` – jazb Aug 08 '19 at 03:01
  • `Driver={INTERSOLV InterBase ODBC Driver (*.gdb)};Server=localhost; Database=localhost:C:\mydatabase.gdb;Uid=myUsername;Pwd=myPassword;` – Chetan Aug 08 '19 at 03:46
  • @JohnB the query is as follows: `using (OdbcCommand com = new OdbcCommand("SELECT * FROM USER", conn)) { using (OdbcDataReader reader = com.ExecuteReader()) { while (reader.Read()) { string word = reader.GetString(0); Console.WriteLine(word); // Word is from the database. Do something with it. } } } ` – tck Aug 08 '19 at 06:36
  • might be permissions related? can you get data from any tables at all? – jazb Aug 08 '19 at 06:40
  • If I run the following query in PHP ` $SQLQuery = "SELECT USERNAME FROM user"; $rs = odbc_exec($conn, $SQLQuery);` I get the following error: `Warning: odbc_exec(): SQL error: [Devart][ODBC][InterBase]Dynamic SQL Error SQL error code = -104 Token unknown - line 1, char 22 user, SQL state S1000 in SQLExecDirect` – tck Aug 08 '19 at 06:48
  • No I can't get data from any tables at all @JohnB. – tck Aug 08 '19 at 06:50
  • is it case sensitive on the col/table names? – jazb Aug 08 '19 at 06:54
  • I can't seem to find anywhere to download the intersolv driver @ChetanRanpariya. Let me keep looking for it. I'll give you feedback once I find it. – tck Aug 08 '19 at 06:55
  • No it is not case sensitive – tck Aug 08 '19 at 06:56
  • It looks like there is something wrong with my USER table. I just created a new table using a query and I ran a SELECT query on that new table and got a result but still can't get anything from USER – tck Aug 08 '19 at 07:27

0 Answers0