5

In my actual project im reading Data from a Filemaker v14 Database. Im getting the Data like that:

command.CommandText = "SELECT * FROM CAR";

//Create new SqlDataReader object and read data from the command.
using (OdbcDataReader reader = command.ExecuteReader())
{
    /*
    * Get and cast the ID
    */
    int counter = 0;
    while (reader.Read() && counter < numberOfOrders)
    {
        SalesOrder s = new SalesOrder();
        s.abNR = reader["Auftrags Nr."].ToString();
        s.artNr = reader["Artikel nr."].ToString();
        s.quantity = reader["Menge"].ToString();
        s.city_country_Coustomer = reader["Stadt"].ToString();
    }
}

This code is running perfectly on the computer I'm developing on.

If I put my project to my IIS this error occurs:

Arithmetic operation resulted in an overflow.

in this line:s.abNR = reader["Auftrags Nr."].ToString();

I already checkt the dsn on both my computer and the server. Both seem to be the same.

The conection is created like that:

conn = new OdbcConnection("DSN=FILEMAKER1;Uid=Test;Pwd=tset");
conn.Open();

command = conn.CreateCommand();

Im looking forward to your answers!

EDIT:

This is my SalesOrder-Class:

public class SalesOrder
{
    public string abNR { get; set; }
    public string artNr { get; set; }
    public string quantity { get; set; }
    public string city_country_Coustomer { get; set; }
}

EDIT 2:

Sample Data for a SalesOrder:

Aufrags Nr. | Artikel nr. | Menge | Stadt   |
------------+-------------+-------+---------+
  168953    |   508800    |   2   | Berlin  |
------------+-------------+-------+---------+
  167996    |   508850    |   4   | München |
------------+-------------+-------+---------+
  FF8957    |   509010    |   1   | Berlin  |

EDIT 3:

[OverflowException: Die arithmetische Operation hat einen Überlauf verursacht.] System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i) +359 System.Data.Odbc.OdbcDataReader.GetValue(Int32 i) +57 System.Data.Odbc.DbCache.AccessIndex(Int32 i) +82
System.Data.Odbc.OdbcDataReader.GetValue(Int32 i) +38
Produktionscockpit.SQL.FilemakerController.getActualSalesOrders(Int32 numberOfOrders) in c:\Dev\ProductionCockpit\Produktionscockpit\SQL\FilemakerController.cs:56 Produktionscockpit.Home.addSalesOrderTabelContent() in c:\Dev\ProductionCockpit\Produktionscockpit\default.aspx.cs:79
Produktionscockpit.Home.Page_Load(Object sender, EventArgs e) in c:\Dev\ProductionCockpit\Produktionscockpit\default.aspx.cs:21
System.Web.UI.Control.LoadRecursive() +116
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2910

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Felix Gerber
  • 1,615
  • 3
  • 30
  • 40
  • What does your `SalesOrder` class look like? Additionally what data type is your `Aufttrags Nr.` column? If it's larger than `Int32.Max`, you might need to explicitly convert it to something like a `long` prior to storing it. – Rion Williams May 11 '16 at 14:36
  • @RionWilliams Thanks for your fast response, I editet my post – Felix Gerber May 11 '16 at 14:39
  • No problem. Can you elaborate on what datatype your `Aufttrags Nr.` column is? – Rion Williams May 11 '16 at 14:42
  • @RionWilliams Its type is text – Felix Gerber May 12 '16 at 06:34
  • Does `OdbcDataReader` have similar methods as for instance `SqlDataReader`? If so, what happens if you try to use `reader.GetString(0)` (assuming *Auftrags Nr.* is the first column)? This is not an answer but, possibly, a workaround... – user1429080 May 19 '16 at 06:40

7 Answers7

6

I was reading a bit about this, and there's a problem with with connecting between 32-bit and 64-bit. Is your application being compiled for x86? Assuming you are using a 32-bit ODBC data source.

From what I see in other people with the same problem (I never experienced this) you can fix it by either moving your application to 32 bits (if the data source is 32 bits) or someone also uninstalled the 64-bit version of filemaker and installed the 32-bit.

It's likely this is the problem, but I can't really give you a proper solution since I don't know your environment.

Itzack
  • 831
  • 6
  • 3
  • Thanks for your answer! It looks like this is going into the right direction. I just recognized, that my IIS is using the 64 Bit driver and my Visual Studio is using the 32 Bit driver. I changed everything to 64bit. The error is stil the same, but now also in Visual Studio. That makes the debugging a bit more easy. – Felix Gerber May 24 '16 at 07:55
  • 1
    Use the 32-bit driver and a *32-bit application pool* in IIS [link](http://www.foliotek.com/devblog/content/images/wp-content/uploads/2011/08/enable32-1024x749.png) – Andrés Robinet May 25 '16 at 07:59
  • 1
    You were right. Our Sysadmin deactivated 32bit mode in IIS. The IIS always used the 64bit driver. Thanks your hint brought me into the right direction! – Felix Gerber May 25 '16 at 08:47
  • 1
    If connecting to an **Informix** database, IBM [list this as the issue](http://www-01.ibm.com/support/docview.wss?crawler=1&uid=swg1IC73807). – MPaul Jun 07 '19 at 15:38
3

If you are receiving an ArithmeticOverflow, it sounds like .NET is having trouble determining the type of your Aufttrags Nr. column and is guessing incorrectly.

If this column is a Number then there are a wide range of .NET data types that it could map to :

enter image description here

You might consider trying to read it as an Int64 via the Convert.ToInt64() method explicitly before outputting it as a string :

s.abNR = Convert.ToInt64(reader["Auftrags Nr."]).ToString();

Or if you expect the value to be a floating-point number, you could try using a Decimal via the Convert.ToDecimal() method :

s.abNR = Convert.ToDecimal(reader["Auftrags Nr."]).ToString();

With Regards to Connecting

Since the title of your question explicitly asks about connecting to a FileMaker database, you can check to ensure that your connection string is correct here and an example Filemaker Pro connection string below :

Driver=FileMaker Pro;AllAsText=0;ApplicationUsingThreads=1;FetchChunkSize=100;
FileOpenCache=0;IntlSort=0;MaxTextlength=255;ServerAddress=127.0.0.1;
TranslationOption=0;UseRemoteConnection=1;

Although it seems like your primary issues aren't related to connectivity.

Rion Williams
  • 74,820
  • 37
  • 200
  • 327
  • Thanks for your fast Response! I tried both of your suggestions. While its working on my local pc with the visual studio webserver, its still didn't working on the webserver I'm using. The error is still the same. The error appears for each of the four lines I'm trying to read the data. Also thanks for your advice with the titel, something went wrong there, I should change that. – Felix Gerber May 12 '16 at 07:09
  • By using your connection string adive i get an OdbcException wich is saying: "ERROR [08S01] [FileMaker][FileMaker] Failed to connect to listener (3)" – Felix Gerber May 12 '16 at 07:10
  • Do you have any sample data for what your table looks like? If the value is being stored as text, then there shouldn't be any conversions / arithmetic overflow issues. It seems like something else might be wrong, consider posting your entire code as well as some sample data, which might help. – Rion Williams May 12 '16 at 10:39
  • I addet sample data to my post in EDIT 2. Also checked the datatype of those fields, and they are all Filemaker text. – Felix Gerber May 12 '16 at 11:34
  • And its still the same problem, its working out of Visual Stuido on my computer but not on the IIS running on my webserver.... – Felix Gerber May 12 '16 at 11:39
  • 1
    If it works locally but not when deployed on IIS, that would make me inclined to believe there was an issue with connecting to the database itself, but that isn't what your error indicates. Have you checked the Event Viewer to see if you can get any more information like a StackTrace on the error in question? – Rion Williams May 12 '16 at 12:15
  • I addet the StackTrace to my post, see Edit 3. – Felix Gerber May 13 '16 at 09:38
1

The stack trace System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i) you provided drives me to conclusion that the problem is that the TEXT type does recognized by the ODBC GetSqlType. The difference in behaviour may be explained by different version of your ODBC driver or it default settings. Check the version and the settings in both environments.

As a work around you may try to CAST your fields to some known types. For example,

SELECT CAST(C.[Aufrags Nr.] as NVARCHAR(MAX)) as [Aufrags Nr.], .... FROM CAR C

Choose appropriate column type depending on what SQL server (or the ODBC source) you query.

Sergey L
  • 1,402
  • 1
  • 9
  • 11
  • Thanks for your answer! But as soon as I'm using this, I get an OdbcException wich says "ERROR [42000] [FileMaker][FileMaker] FQL0001/(1:13): There is an error in the syntax of the query." – Felix Gerber May 23 '16 at 07:18
1

I was having almost similar problem once and after trying lot of things like converting to long etc etc, this finally solved my problem although I am not sure how it solved?

abNR = reader["Auftrags Nr."] + "";

I replaced ToString() with + "";

Mukesh Adhvaryu
  • 642
  • 5
  • 16
1

Having some problems with 64-bit ODBC DSN I've just created 32-bit DSN on 64-bit Windows by running C:\WINDOWS\SYSWOW64\odbc32.exe instead of default ODBC tool. Worked fine.

Serg
  • 22,285
  • 5
  • 21
  • 48
  • Thanks for your answer! How can I make the 64Bit IIS use the 32 bit FMODBC-Driver and DSN? Like that my application cant find the dsn – Felix Gerber May 24 '16 at 10:05
  • IIS configuration is beyond my experience, sorry. Mine was desktop application, Mapinfo. I only noted that on my desktop all User DSNs are listed in registry all together under `HKEY_CURRENT_USER\Software\ODBC\ODBC.INI` while system DSNs use different keys for 32-bit and 64-bit. Probably you need user DSN under IIS account. – Serg May 24 '16 at 12:55
1

There might be a problem with your column naming convention: for that change your query to this

command.CommandText = "SELECT *, [Auftrags Nr.] as AuftragsNr, [Artikel nr.] as ArtikelNr FROM CAR";

//Create new SqlDataReader object and read data from the command.
using (OdbcDataReader reader = command.ExecuteReader())
{

int counter = 0;
while (reader.Read() && counter < numberOfOrders)
{
    SalesOrder s = new SalesOrder();
    s.abNR = reader["AuftragsNr"].ToString();
    s.artNr = reader["ArtikelNr"].ToString();
    s.quantity = reader["Menge"].ToString();
    s.city_country_Coustomer = reader["Stadt"].ToString();
}
}
Numan Ali
  • 223
  • 2
  • 13
0

The ODBC driver determined the data type of the column called AuftragsNr as int and fails on the 3rd line. Try to use the GetString method.

Dexion
  • 1,101
  • 8
  • 14