SQL Select from one sql server into another without linked servers in vb.net

Hi,

I need help finishing this import from one sql server to another with no linked servers. I got this far but I can't get passed the errors when importing:

  Dim SQLConnection As New SqlConnection()
        Dim ConnString2 As String = "Data Source=data;Initial Catalog=cat; User Id=sa; Password=blabla;"
        SQLConnection.ConnectionString = ConnString2

        Try
            SqlConnection.Open()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try


        Dim expr As String = "SELECT City, State, Zip, home_phone as Phone FROM dbo.people"

        Dim objCmdSelect As SqlCommand = New SqlCommand(expr, SQLConnection)

        
        Dim objDR As SqlDataReader

        Dim SQLconn As New SqlConnection()
        Dim ConnString As String = ""Data Source=data2;Initial Catalog=cat2; User Id=sa; Password=blabla;"
        SQLconn.ConnectionString = ConnString
        SQLconn.Open()




        Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(SQLconn)
            bulkCopy.DestinationTableN<wbr ></wbr><wbr ></wbr>ame = "Import"

            Try
                objDR = objCmdSelect.ExecuteReader<wbr ></wbr><wbr ></wbr>
                bulkCopy.WriteToServer(obj<wbr ></wbr><wbr ></wbr>DR)
                objDR.Close()
                SQLconn.Close()



                MsgBox("Import Completed Successfully!!")

Open in new window


Essentially I need to run an sql from one server

take those results and insert it into another server that is not linked (can't be linked)

I usually use an insert when it is a linked server but I can't do that in this case...

Does anyone know a good workaround?

Thanks
tenchulyoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Do you need to do that by code?
You can use SQL Server Management Studio Import/Export Data Wizard.
ExportData.PNG
Ioannis ParaskevopoulosCommented:
Hi,

This sounds like a need for an ETL tool.

If you have an SQL Server other than the Express edition, it should have SSIS, which would allow you to create packages to do that job for you.

If you have the express edition, then you are limited to the import export wizard, mentioned by Vitor. I am not sure but i think this is mostly useful for inserts and not merging two tables. If you only want to insert, then this might be good for you.

A third option would be to use any other third party ETL software. You may find a few community versions that would do simple tasks as the one you describe for free. A quick search for "community ETL" on google returned in order :
Pentaho Kettle (I am not sure this is free)


Now if you would want to do it yourself in a programmatic way, there is a .NET library called Rhino-ETL. You may want to view some resources for this to see its power :
Video
Powerpoint and Sample project

Giannis
CodeCruiserCommented:
SSIS is another option.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tenchulyoAuthor Commented:
Hey Vitor,

Sorry but yes, It has to be done in code.

Hi Giannis,

Yes, that might work if I re-write everything and add one of those libraries, but your answer is more correct. After many hours yesterday I figured out that my code is correct, the information I was missing is that bulkcopy inserts the data from left to right and so your tabledata must reflect in that order. your query has to be left to right select in order for this to work. Now it works like a charm!

Thanks guys,

Lyo
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.