Azure migration sample code

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data.OleDb;
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Management.Smo;

using System.Data.Odbc;

namespace AzureApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            //Microsoft.SqlServer.Server srv;
            //srv = new Microsoft.SqlServer.Server();
            ////Reference the AdventureWorks2012 database  
            //Database db;
            //db = srv.Databases["AdventureWorks2012"];
            ////Create a new database that is to be destination database.  
            //Database dbCopy;
            //dbCopy = new Database(srv, "AdventureWorks2012Copy");
            //dbCopy.Create();
            ////Define a Transfer object and set the required options and properties.  
            //Transfer xfr;
            //xfr = new Transfer(db);
            //xfr.CopyAllTables = true;
            //xfr.Options.WithDependencies = true;
            //xfr.Options.ContinueScriptingOnError = true;
            //xfr.DestinationDatabase = "AdventureWorks2012Copy";
            //xfr.DestinationServer = srv.Name;
            //xfr.DestinationLoginSecure = true;
            //xfr.CopySchema = true;
            ////Script the transfer. Alternatively perform immediate data transfer  
            //// with TransferData method.  
            //xfr.ScriptTransfer();





            #region Connection
            List<String> listBox1 = new List<String>();
            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Mohan thangella\MS Access to Azure\ForRoland\Site_Tracker_BE_v4_July_2016 - SQL.accdb");
            conn.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM tbl_WP", conn);
            OleDbDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            if (dr.HasRows)
            {
                dt.Load(dr);
                SqlConnection Azcon = new SqlConnection("Server=tcp:chandumtc.database.windows.net,1433;Initial Catalog=Chandu;Persist Security Info=False;User ID=chandu433;Password=pass@word1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
                SqlCommand Azcmd = new SqlCommand();
                Azcon.Open();
                foreach (DataRow item in dt.Rows)
                {
                    Azcmd = new SqlCommand(@"INSERT INTO tbl_WP  VALUES ('" + item.ItemArray[0] + "','" + item.ItemArray[1] + "','" + item.ItemArray[2] + "','" + item.ItemArray[3] + "','" + item.ItemArray[4] + "','" + item.ItemArray[5] + "')", Azcon);
                    Azcmd.ExecuteNonQuery();
                }
                Azcon.Close();
            }
         
         
            #endregion
            #region tablecreation

            #endregion;

            #region Insert record
            //con.Open();
            //cmd = new SqlCommand(@"INSERT INTO MTC_Customer (First_Name, Last_Name) VALUES ('purushotham', 'allam')", con);
            //cmd.ExecuteNonQuery();
            //con.Close();
            #endregion

            #region Read Data
            //cmd = new SqlCommand(@"SELECT * FROM Esempio", connessione);
            //SqlDataReader dr = cmd.ExecuteReader();
            //if (dr.HasRows)
            //{
            //    while (dr.Read())
            //    {
            //        String retVal = dr.GetInt32(0).ToString() + " " + dr.GetString(1);
            //    }
            //}
            //dr.Close();
            //connessione.Close();
            #endregion
        }
    }
}


Comments

  1. Wow... I found this information very helpful for azure migration. Thanks for sharing code through this blog.

    ReplyDelete

Post a Comment

Popular posts from this blog

Basic Plugin Code in D365 using C#

CURD (Create, Update, Retrieve and Delete) Operation in D365 using Power Shell Script

Meta Data Using WebApiRequest