Skip to content

DestinationTableName cannot be a synonym #1070

@cvereker

Description

@cvereker

It is worth adding that the destination table cannot be a synonym (as demonstrated by the code below). (It seems weird that this should be the case)

Sql:
drop table if exists myschema.SimpleTable
drop schema if exists myschema;
go

create schema myschema;
go

create table myschema.SimpleTable(Id int);
go

drop synonym if exists dbo.SimpleTable;
go

create synonym dbo.SimpleTable for myschema.SimpleTable;
go

C#:
var tblData = new DataTable();
tblData.Columns.Add("Id", typeof(int));

        for (var i = 0; i < 100; i++) tblData.Rows.Add(i);

        using (var sqlBulkCopy = new SqlBulkCopy(connectionString) {DestinationTableName = "SimpleTable"})
            sqlBulkCopy.WriteToServer(tblData);

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions