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

  • Home
  • SEARCH
  • 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 152595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:39:06+00:00 2026-05-11T09:39:06+00:00

I have a SQL file added to my VS.NET 2008 project as an embedded

  • 0

I have a SQL file added to my VS.NET 2008 project as an embedded resource. Whenever I use the following code to read the file’s content, the string returned always starts with three junk characters and then the text I expect. I assume this has something to do with the Encoding.Default I am using, but that is just a guess. Why does this text keep showing up? Should I just trim off the first three characters or is there a more informed approach?

public string GetUpdateRestoreSchemaScript() {     var type = GetType();     var a = Assembly.GetAssembly(type);     var script = 'UpdateRestoreSchema.sql';     var resourceName = String.Concat(type.Namespace, '.', script);     using(Stream stream = a.GetManifestResourceStream(resourceName))     {         byte[] buffer = new byte[stream.Length];         stream.Read(buffer, 0, buffer.Length);         // UPDATE: Should be Encoding.UTF8         return Encoding.Default.GetString(buffer);     } } 

Update: I now know that my code works as expected if I simply change the last line to return a UTF-8 encoded string. It will always be true for this embedded file, but will it always be true? Is there a way to test any buffer to determine its encoding?

  • 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. 2026-05-11T09:39:07+00:00Added an answer on May 11, 2026 at 9:39 am

    Probably the file is in utf-8 encoding and Encoding.Default is ASCII. Why don’t you use a specific encoding?

    Edit to answer a comment:

    In order to guess the file encoding you could look for BOM at the start of the stream. If it exists, it helps, if not then you can only guess or ask user.

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

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Basically you need to "merge backwards" - apply a diff… May 11, 2026 at 6:07 pm
  • Editorial Team
    Editorial Team added an answer I think you can forget about checking for null. Instead… May 11, 2026 at 6:07 pm
  • Editorial Team
    Editorial Team added an answer In case "Interact with desktop" on the service is not… May 11, 2026 at 6:07 pm

Related Questions

I have an assembly that is deployed to SQL server that references System.Drawing. Don't
I'm trying to get a stored procedure to work for a co-worker who is
Perhaps naively, I created a class (AdminDatabase) to handle connection to different MS-Access database
I use Netbeans IDE (6.5) and I have a SQLite 2.x database. I installed

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.