Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8074187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:34:20+00:00 2026-06-05T14:34:20+00:00

Note: I am looking for why this is happening and how to fix it,

  • 0

Note: I am looking for why this is happening and how to fix it, I am not looking for a workaround. This appears to be a server(SQL Server or Connection string) issue.

I have a program that is connected to a sql 2008 database (Database A) and I have inline sql that runs that has ints and strings returned and it works fine. But I have been asked to switch to another 2008 database (Database B) and now everything is coming back as a string and I am getting a specified cast is not valid from C# where when I am connected to the sql 2008 (Database A) it does not say this. This is a inline sql statement so the sql statement is not changing and the table schema of the database is the same. Its doing this on int primary keys Anyone have any ideas?

I originally thought the was a 2000 to 2008 issue but I now have the some problem on 2008 as well. Both databases are on the same instance of sql server these are the connection strings

Connection Strings

  Server=Server01\instance;Database=Fraud_Micah; Trusted_Connection=yes <- Server 2008 (this one does not)
  Server=Server02\instance;Database=Fraud; Trusted_Connection=yes <- Server 2008 (this one works)

Both databases are at DB compatibility_level of 100

The select Statement

select *, delimeter, file_filetype.LocalPath, ArchiveDir, EmailList
from file_importtable 
join file_filetype on file_importtable.FileTypeID = file_filetype.ID
where importsuccessdate is null and transferdate is not null
and remotediscoverdate is not null 
and OriginalFileName in ('Test987.xml.pgp')

fileTypeID is where its breaking -> InvalidCastException: Specified cast is not valid.

C# Code (Note reader is type SQLDataReader)

if (!(reader.IsDBNull(reader.GetOrdinal("FileTypeID"))))
{
    file.FileTypeID = reader.GetInt32(reader.GetOrdinal("FileTypeID"));
}

Here is the column definition: [FileTypeID] [int] NULL, there is no null values in the table.

I don’t think the C# code comes from this, its a int? public int? FileTypeID { get; set; }

In debug mode: reader["FileTypeID"] -> “1” it is in fact a string but why when I connect to a 2008 database would it return a 1 instaed of a “1”

2008 Table A Def

[ProcessSuccessDate] [datetime] NULL,
[ProcessSuccessUser] [datetime] NULL,
[FileTypeID] [int] NULL,
[HoldDate] [datetime] NULL,

2008 Table B Def

ProcessSuccessDate] [datetime] NULL,
[ProcessSuccessUser] [datetime] NULL,
[FileTypeID] [int] NULL,
[HoldDate] [datetime] NULL,

file.FileTypeID = (int)reader["FileTypeID"]; yields the same result.

Doing a

     file.FileTypeID (int)reader.GetInt32(reader.GetOrdinal("FileTypeID"));

does work but I don’t want to do that for every column that already should be coming back as a int also writing sql like this

     select Convert(int, FileTypeID) as FileTypeId, delimeter, file_filetype.LocalPath, ArchiveDir, EmailList

can get around the issue as well, however I want to know why I have to do this if I already set the type as a int in the table. I might as well put all the types as strings in the table. At this point I am not looking for a workaround I want to understand why its not working like it should be.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:34:21+00:00Added an answer on June 5, 2026 at 2:34 pm

    In the scheme of things I desided to delete the table and recreate it using

    [script table as] -> [create]

    from the same table that was giving me issues, then a reinserted all the same data. This resolved the issue. So I don’t believe the DML of the Table changed and the data did not change either but this is what resolved my issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: If possible, I am looking for a pure SQL query solution so I
Note: This question has broadened in scope from previous revisions. I have tried to
I have a partial now looking like this: <%= render(:partial => 'order', :object =>
I have been looking through this fantastic article: http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/ While being fantastic, it is
NOTE: Originally had this listed as a memory leak. After looking into this deeper,
Note that I'm really looking for an answer to my question. I am not
I have a weird situation happening that I'm not quite understanding. I have a
I have a base class looking like this: public class BaseController : Controller {
Please note this code was not written by me. Otherwise I would not be
Not sure how to ask this question, but here goes. Say I have: var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.