Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8754661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:40:35+00:00 2026-06-13T13:40:35+00:00

I have written a C# code to transfer tables between two remote servers using

  • 0

I have written a C# code to transfer tables between two remote servers using SMO, what I want to know is that is there anyway to check if the table already exists in the destination server with the exact schema, column names, data types, constraints and everything. Then I wouldn’t have to drop the existing table every time and create new ones.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:40:36+00:00Added an answer on June 13, 2026 at 1:40 pm

    Try this piece of code snippet:

    Server srv1 = new Server("<server_location>");
    srv1.ConnectionContext.LoginSecure = false;
    srv1.ConnectionContext.Login = "<username>";
    srv1.ConnectionContext.Password = "<password>";
    srv1.ConnectionContext.Connect();
    Database sourceDb = srv1.Databases["<database_name>"];
    Table sourceTbl = sourceDb.Tables["<table_name>"];
    
    Server srv2 = new Server("<server_location>");
    srv2.ConnectionContext.LoginSecure = false;
    srv2.ConnectionContext.Login = "<username>";
    srv2.ConnectionContext.Password = "<password>";
    srv2.ConnectionContext.Connect();
    Database destinationDb = srv1.Databases["<database name>"];
    Table destinationTbl = sourceDb.Tables["<table_name>"];
    
    var isMatched = CompareTables(sourceTbl, destinationTbl);    
    

    Compare Method:

    bool CompareTables(Table source, Table destination)
    {
        // Column count doesn't match
        if (!source.Columns.Count.Equals(destination.Columns.Count))
            return false;
    
        // Assuming the order of the Columns are same in both the Tables
        for (int i = 0; i < source.Columns.Count; i++)
            if (!source.Columns[i].Equals(destination.Columns[i]))
                return false;
    
        // Constraints count doesn't match
        if (!source.Checks.Count.Equals(destination.Checks.Count))
            return false;
    
        // Assuming the order of the Contraints are same in both the Tables
        for (int i = 0; i < source.Checks.Count; i++)
            if (!source.Checks[i].Equals(destination.Checks[i]))
                return false;
    
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some code that loads an XML document using an XmlDocument object
I have a file transfer code written in C using windows sockets which seems
I have written code for passing file descriptors between unrelated processes using streams. The
I have written code that opens 16 figures at once. Currently, they all open
I have written code to perform a function that could take a while to
I have written code that changes the color of a mark the user places
I have written code for server and client sockets. I have used threads using
I have written code in C# which is exceeding page width, so I want
We have a data transfer between 2 systems that can take upto a few
I have written code for performing calculations. There is a loop in the code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.