Solved

ASP.NET error "Failure creating file."

Posted on 2011-02-16
3
797 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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, as well as the share.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

15 Experts available now in Live!

Get 1:1 Help Now