Solved

ASP.NET error "Failure creating file."

Posted on 2011-02-16
3
801 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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!
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

763 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