Link to home
Start Free TrialLog in
Avatar of melli111
melli111Flag for United States of America

asked on

ASP.NET error "Failure creating file."

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);
                }
            }
        }
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

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?
Avatar of melli111

ASKER

Yes, teh file itself has rights.  Could it possibly be that the fodler on the network does not have sufficient priviliges?
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial