UNC path is Replaced by Mapped Drive

224 Views Asked by At

I am attempting to get data from an Access database and send it to an identical table in a SQL database.

using (OleDbConnection oleDbConnection = new OleDbConnection(sourceConnectionString))
{
    using (OleDbCommand oleDbCommand = new OleDbCommand($"SELECT * FROM {sourceTableName}", oleDbConnection))
    {
        oleDbConnection.Open();

        using (OleDbDataReader reader = oleDbCommand.ExecuteReader())
        {
            using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(destinationConnectionString))
            {
                sqlBulkCopy.DestinationTableName = destinationTableName;
                sqlBulkCopy.WriteToServer(reader);
            }
        }
    }
}

The sourceConnectionString contains a data source equal to a UNC path (e.g. \\server\fileshare\folder\accessDB.accdb). When I step through the code and get to oleDbCommand.ExecuteReader(), an exception is thrown saying

Y:\folder\accessDB.accdb is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

I have no idea why the UNC path (\\server\fileshare) was replaced with a mapped drive (Y:\). There is nothing in my code to set or use a mapped drive. All properties in oleDbconnection and oleDbCommand reference the UNC path.

If I create a mapped drive to the UNC path. The oleDbCommnand.ExecuteReader() will work and no exceptions are thrown.

I'd appreciate any ideas why the UNC path is defaulting to a mapped drive. I assume it is a default on the server or my PC that the network team set up. I have no clue how to verify it. For now, I'll have to ensure the end user's PC has a Y: drive mapped to the fileshare on the server.

0

There are 0 best solutions below