473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

C# Import xls file into sql server

Hi can anybody tell what is error in following code, its running through .Net 2005 editor fine,
but when running on browser gives error:
No error message available, result code: E_FAIL(0x80004005).
Expand|Select|Wrap|Line Numbers
  1.  try
  2.         {
  3.             // Create Connection to Excel Workbook
  4.  
  5.             OleDbConnection connection = new OleDbConnection(excelConnectionString);
  6.  
  7.             if (connection.State == ConnectionState.Closed)
  8.             {
  9.  
  10.                 connection.Open();
  11.                      }
  12.  
  13.             OleDbCommand command = new OleDbCommand("select Name,Age,City,Phone FROM [Data$]", connection);
  14.  
  15.             // Create DbDataReader to Data Worksheet
  16.  
  17.             OleDbDataReader dr = command.ExecuteReader();
  18.  
  19.                      // SQL Server Connection String
  20.             string sqlConnectionString = "Data Source=localhost;database=demo;user id=sa;pwd=sa";
  21.  
  22.             // Bulk Copy to SQL Server
  23.  
  24.             SqlBulkCopy bulkcopy = new SqlBulkCopy(sqlConnectionString);
  25.  
  26.                      bulkcopy.DestinationTableName = "ExcelData";
  27.  
  28.             //            bulkCopy.WriteToServer(dr);
  29.             bulkcopy.WriteToServer(dr);
  30.             bulkcopy.Close();
  31.             if (!dr.IsClosed)
  32.                 dr.Close();
  33.  
  34.    Response.Write("Data Imported From Xls file");
  35.             if (connection.State == ConnectionState.Open)
  36.                 connection.Close();
  37.         }
  38.  
  39.         catch (Exception ex)
  40.         {
  41.             Response.Write(ex.Message);
  42.         }
Dec 14 '07 #1
4 10896
Frinavale
9,735 Expert Mod 8TB
I think it might have something to do with your connection string.

See this article. It could really help you out.
Dec 14 '07 #2
I think it might have something to do with your connection string.

See this article. It could really help you out.
Thanks Frinavale,

It works,
I had not put the file in my application folder,
I had just put the file in my application folder and its worked

Thanks for help
Dec 15 '07 #3
I'm currently struggling to upload the Excel sheet data to the SQL Server using .Net. Please help me in provide the source code for it. I'll be very thnakful for the timely help.


Thanks Frinavale,

It works,
I had not put the file in my application folder,
I had just put the file in my application folder and its worked

Thanks for help
Oct 22 '08 #4
Frinavale
9,735 Expert Mod 8TB
I'm currently struggling to upload the Excel sheet data to the SQL Server using .Net. Please help me in provide the source code for it. I'll be very thnakful for the timely help.
This forum is dedicated to helping you understand your problems so that you can create your own solution. Please attempt to solve the problem before asking for help with it so that we can address any difficulties you face.

What have you tried so far?
What problems have you encountered?

Please post any code that you think might be causing the problem (remember to use code tags when posting code snippets)

-Frinny
Oct 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Benny | last post by:
Dear All, I am performing a data import on the SQL server. Due to fact that I use the excel file as a source. Some of cells in excel are actually empty, they become NULL fields after importing...
4
by: Kevin Forbes | last post by:
Hi there, When importing a text file using SQL Server, how do I specify the path to a file on the same remote server that SQL Server is running on? I tried //c:/filename but that doesn't seem to...
2
by: jet | last post by:
Hi, Maybe this is an easy task, but I'm having a really hard time figuring out how to do this. I'm a complete newbie to SQL Server. I have a database dump file from MySQL that's in .sql...
1
by: Chris | last post by:
Background: I am using a MS Access 2000 front end with SQL Server 8.0 back end. I have the requirement to import all text files (regardless of filename) from a given folder on the network into a...
1
by: Ralph Noble | last post by:
I have two avenues to access my primary SQL Server. (I work remotely using a VPN connection.) Usually, I hit the server from my local machine but I also login to a desktop machine inside the...
2
by: s.hong | last post by:
Hello? On the ASP.NET, I can use the class by import declation on the top of page. <%@ page language="vb" explicit="true" aspcompat="false" debug="true"%> <%@ import namespace="System.Data" %>...
1
by: David Berry | last post by:
Hi All. I'm looking for any help or sample code that can show me how to make a file import wizard in ASP.NET (VB preferred) like the one that MS Access uses. I'm working on a web site where the...
4
by: BostonNole | last post by:
I am looking for suggestions on the most efficient way to import 7 different fixed width files into a DataSet. Not all at the same time. One file at a time, but the format could change from file...
7
by: Randy | last post by:
Folks: We have a web-based app that's _really_ slowing down because multiple clients are writing their own private data into a single, central database. I guess the previous programmer did...
0
by: A3AN | last post by:
Hi. I receive a database backup on a daily basis. I then import this dump on another server which I use for software development. There is two db's being hosted on this server. We test software...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.