Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to import some data from an excel file to a SQL table using the below code
C++
public void ImportData()
{
    // Connection String to Excel Workbook
    string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\stagingserver\abc\UPLOAD\MyFile.xls;Extended Properties=""Excel 8.0;HDR=YES;IMEX=1""";
    OleDbConnection xlConn = new OleDbConnection(excelConnectionString);
    OleDbCommand xlCommand = new OleDbCommand("select col1, col2 from [Sheet1$]", xlConn);
    xlConn.Open();

    using(DbDataReader dr = xlCommand.ExecuteReader())
    {
        using(SqlBulkCopy copyData = new SqlBulkCopy(MYConnectionString))
        {
            copyData.DestinationTableName = "MY_TABLE";
            copyData.WriteToServer(dr);

            copyData.Close();
        }
        dr.Close();
        dr.Dispose();
    }
    xlCommand.Dispose();
    xlConn.Close();
    xlConn.Dispose();
}


. This works fine from my local system. When trying the same from the server no rows get inserted. There is no error also... Any thoughts will be appreciated.
Posted
Updated 1-Dec-10 5:11am
v3

If you use a DTS package you might want to check the filename of the source excel file. The file could exist locally, but just doesn't on the server.

Good luck!
 
Share this answer
 
I agree with E.F. Check the paths of the import file and the format file if used. Most of the time something works locally but not remotely is

A. Paths
B. Connection strings.
C. Permissions.

Do you mean there is no error on the server? I would recommend checking the server log.

Are you doing this via command line or in code? Do you mean there are no exceptions in your code or displayed via command line?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900