Solved

ASP.NET error "Failure creating file."

Posted on 2011-02-16
3
799 Views
Last Modified: 2012-05-11
I am using a program that that opens an Excel file and reads it and writes the contents to a SQL Server database.  The code I am using is as follows:


string connectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=//server/EstimateWBS/template.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
        using (OleDbConnection connection = new OleDbConnection(connectionstring))
        {
            OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);
            connection.Open();    <----------------------- ERROR OCCURS
            using (DbDataReader datareader = command.ExecuteReader())
            {
                string SQLconnectionstring = "Data Source=datasource;Initial Catalog=table;Persist Security Info=True;User ID=userid;Password=password";
                using (SqlBulkCopy copy = new SqlBulkCopy(SQLconnectionstring))
                {
                    copy.DestinationTableName = "WBS";
                    copy.WriteToServer(datareader);
                }
            }
        }
0
Comment
Question by:melli111
  • 2
3 Comments
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 34911013
Maybe it's just a typo, but those should be back-slashes in the file's path in the connection string (I assume you're on Windows).

string connectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\server\EstimateWBS\template.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

And this file exists, and whatever user your program/website is running as has rights to the file?
0
 
LVL 15

Author Comment

by:melli111
ID: 34911560
Yes, teh file itself has rights.  Could it possibly be that the fodler on the network does not have sufficient priviliges?
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 34911714
Yes, as well as the share.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now