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 8324269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:00:18+00:00 2026-06-09T00:00:18+00:00

I’m getting an error when trying to upload a .csv to my sql server

  • 0

I’m getting an error when trying to upload a .csv to my sql server using asp.net uploadfile tool. The application is on the localhost and the SQL Server is NOT located on the same machine. It creates the table inside the database with the proper columns, just doesn’t fill it up with the data. Here is the code error: “Cannot bulk load because the file “c:\users\visual studio 2010\Projects\webImport\webImport\UploadedCSVFiles\Employee.csv” could not be opened. Operating system error code 3(The system cannot find the path specified.).

Here is the code behind:

        private void LoadDataToDatabase(string tableName, string fileFullPath, string delimeter)
    {
        string sqlQuery = string.Empty;
        StringBuilder sb = new StringBuilder();
        sb.AppendFormat(string.Format("BULK INSERT {0} ", tableName));
        sb.AppendFormat(string.Format(" FROM '{0}'", fileFullPath));
        sb.AppendFormat(string.Format(" WITH ( FIELDTERMINATOR = '{0}' , ROWTERMINATOR = '\n' )", delimeter));

        sqlQuery = sb.ToString();
        using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
        {
            sqlConn.Open();
            SqlCommand sqlCmd = new SqlCommand(sqlQuery, sqlConn);
            sqlCmd.ExecuteNonQuery();
            sqlConn.Close();
        }
    }

    protected void BTNImport_Click1(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            FileInfo fileInfo = new FileInfo(FileUpload1.PostedFile.FileName);
            if (fileInfo.Name.Contains(".csv"))
            {

                string fileName = fileInfo.Name.Replace(".csv", "").ToString();
                string csvFilePath = Server.MapPath("UploadedCSVFiles") + "\\" + fileInfo.Name;

                //Save the CSV file in the Server inside 'MyCSVFolder' 
                FileUpload1.SaveAs(csvFilePath);
                //Fetch the location of CSV file 
                string filePath = Server.MapPath("UploadedCSVFiles") + "\\";
                string strSql = "SELECT * FROM [" + fileInfo.Name + "]";
                string strCSVConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";" + "Extended Properties='text;HDR=YES;'";
                // load the data from CSV to DataTable 
                OleDbDataAdapter adapter = new OleDbDataAdapter(strSql, strCSVConnString);
                DataTable dtCSV = new DataTable();
                DataTable dtSchema = new DataTable();
                adapter.FillSchema(dtCSV, SchemaType.Mapped);
                adapter.Fill(dtCSV);

                if (dtCSV.Rows.Count > 0)
                {
                    CreateDatabaseTable(dtCSV, fileName);
                    Label2.Text = string.Format("The table ({0}) has been successfully created to the database.", fileName);

                    string fileFullPath = filePath + fileInfo.Name;
                    LoadDataToDatabase(fileName, fileFullPath, ",");
                    Label1.Text = string.Format("({0}) records has been loaded to the table {1}.", dtCSV.Rows.Count, fileName);
                }
                else
                {
                    Label3.Text = "File is empty.";
                }
            }
            else
            {
                Label3.Text = "Unable to recognize file.";
            }

        }
    }

I’m guessing it has something to do with the Server.MapPath. Is it possible to route the file to be saved and executed on a different server then the application. if that makes any sense.

  • 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-09T00:00:20+00:00Added an answer on June 9, 2026 at 12:00 am

    If you use the TSQL form of bulk load, that code executes on the SQL server, so the file path you specify is relative to the DB server.

    In your case, I think you should look at SqlBulkCopy and the “Fast CSV Reader” from code project; they work very well together. Then you are processing the CSV on your web-server, and sending the bulk stream to the SQL server via a very efficient API.

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

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.