Cannot access database through linked server

ado.net c# exception-handling linked-server sqlbulkcopy

Question

I am using the SqlBulkCopy Feature to store bulk data in to Sql database.

For Ex: bulkCopy.DestinationTableName = "employeetable". This code works fine. But In a scenario, where i don't have access to the Destination database directly through Connection string. A linked server is only provided to the destination database. When i am trying to connect the Destination database through the Linked server(Code Below)

For Ex:

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destcon, SqlBulkCopyOptions.Default, sqltran))
{
    bulkCopy.DestinationTableName = "LinkedSeverName.database.dbo." + employeetable;  
    bulkCopy.WriteToServer(dt);
}

I get the following error,

Cannot access destination table 'LinkedSeverName.database.dbo.employeetable'. ---> System.Data.SqlClient.SqlException: Could not locate entry in sysdatabases for database 'XXX'. No entry found with that name. Make sure that the name is entered correctly

Is there any other way to overcome this error and achieve the task. Any help is highly appreciated.

Popular Answer

One thing you can look into is, four part name is case sensitive. Make sure that you are specifying correct case.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why