logo
down
shadow

Insert data from one DB into another on a different server - servers not linked


Insert data from one DB into another on a different server - servers not linked

By : user2957002
Date : November 22 2020, 03:03 PM
fixed the issue. Will look into that further I am trying to copy some selected data from one DB, set on a server that is expiring on Jan 1st, into another so that I can preserve it. The second DB is on a different server, different host etc - I no longer have access to the first one, but only know the various locations of the items I require.
code :
// Connection 1
$link = mysql_connect('XXXXaddressXXXX', 'XXXXuserXXXX', 'XXXXXXpwXXXXX');  //edited out the access details for security
mysql_select_db('sfi_db', $link) or die("Can't connect to first database");

// Connection 2
$dBIP='XXXAddressOfSecondServerXXXX';
$dBADN='XXXXUserofSecondServerXXXX';
$dBPWD='XXXXPWofSecondServer';
$dBDBS="XXXXDBnameXXXX";

$CONNECTW=mysql_connect($dBIP,$dBADN,$dBPWD);
mysql_select_db($dBDBS, $CONNECTW)  or die("Can't connect to second database");;


$query = "SELECT t.entry_id, t.title, t.year, t.month, t.day, d.field_id_1, d.field_id_2, d.field_id_3 FROM sfi_db.exp_channel_titles t LEFT JOIN sfi_db.exp_channel_data d ON t.entry_id = d.entry_id WHERE d.field_id_5='Latest-Updates'";
$results=mysql_query($query,$link); 
while($row=mysql_fetch_row($results)){
    $id=$row[0];
    $title = $row[1];
    $year = $row[2];
    $month = $row[3];
    $day = $row[4];
    $summary = $row[5];
    $body = $row[6];
    $image = $row[7];


    mysql_query("INSERT INTO $dBDBS.newsimport (id,title,year,month,day,summary,body,image_url) VALUES ('$id','$title','$year','$month','$day','$summary','$body','$image')",$CONNECTW);

    }


Share : facebook icon twitter icon
Move data accross SQL Servers with DTS packages or linked servers

Move data accross SQL Servers with DTS packages or linked servers


By : user446909
Date : March 29 2020, 07:55 AM
Any of those help you can use BCP to export and then import data.
How to access Postgres data from SQL Server (linked servers)

How to access Postgres data from SQL Server (linked servers)


By : Naren
Date : March 29 2020, 07:55 AM
this one helps. OPENQUERY is definitely a way to do it; what issues are you having with dynamic SQL?
Perhaps create a temp table in server 1, import a filtered subset of the PostgreSQL data using a parameterized query into that temp table, and then join onto your temp table in your final SQL query.
How to create a table using the INSERT INTO clause using linked servers in SQL Server Management Studio

How to create a table using the INSERT INTO clause using linked servers in SQL Server Management Studio


By : Sakshi
Date : March 29 2020, 07:55 AM
With these it helps There are two mistakes in your query
1.INTO clause support maximum of 2 prefixes. You cannot include SERVER NAME
code :
DATABASE_NAME.SCHEMA_NAME.TABLE_NAME
SELECT *
INTO [Reporting].[dbo].[NewTable]
FROM [linked].[Main].[dbo].[Orders];
Test connection of linked servers and return connected linked server(s)

Test connection of linked servers and return connected linked server(s)


By : Dimitris T
Date : March 29 2020, 07:55 AM
Does that help Changed a few things in your code... give this a shot.
IsOff just means the connection failed. I added a where clause to look at Linked Servers only I've never seen a cursor as a variable so I removed that and the other variables I didn't need Used a TRY/CATCH since sys.sp_testlinkedserver raises and exception if it doesn't success. Return the reason why it failed Stored all the results into a table variable and only returned the failures
code :
DECLARE @name NVARCHAR(100)

declare @table table (IsOff int, ServerName varchar(100), TheError varchar(4000))


DECLARE getid CURSOR FOR
SELECT  name FROM sys.servers where is_linked = 1


OPEN getid

FETCH NEXT FROM getid INTO @name
WHILE @@FETCH_STATUS = 0

BEGIN

    begin try
        exec sys.sp_testlinkedserver @name
    end try

    begin catch
        insert into @table
        values
        (1,@name,ERROR_MESSAGE())
    end catch

FETCH NEXT FROM getid INTO @name

END

CLOSE getid
DEALLOCATE getid

select ServerName, TheError from @table where IsOff = 1
How do you remove linked server metadata cache when there are no defined linked servers?

How do you remove linked server metadata cache when there are no defined linked servers?


By : Adam W. P. Hackett
Date : March 29 2020, 07:55 AM
I wish this helpful for you Backup the data and drop the offending table in the Progress OpenEdge system. Create a new table and load the data.
Now, the issues is resolved.
Related Posts Related Posts :
  • Find TimeDiff between two dates
  • Get Values From Multidimensional PHP Array inside Javascript
  • Static HTML, CSS, and JS to backend admin access
  • How can I manipulate HTML tags in PHP?
  • When to use Else and when to use Elseif?
  • PHP regex which matches only strings with specific endings
  • Tablet detection with detect mobile browser script?
  • Execute mulltiple expressions in conditional operator
  • php \n new line no show well
  • How to add Smarty templating engine to CodeIgniters 3 framework?
  • Am I maxing out possible data insert
  • Redirect to homepage without changing address bar URL
  • What is the best user-Id Value for a MySql "users" table
  • PHP $_COOKIE is only available in one directory
  • php regular expressions documantation
  • cannot import too large sql file to mysql
  • not getting appilcation/json in content-type in header
  • Only the first data display from my database but other shows but not on a table
  • Is it possible to have a print button link as the content of the mail
  • how to extract full mail address in imap php
  • Alternative to output buffering to put eval'd code into a variable
  • how to run wordpress php snippet mysql update command from ssh and/ultimately cron
  • how to get xml tag by name
  • ModSecurity maximum post limits (PCRE limit errors)
  • Call controller/action in event listener
  • How to improve performance of contacting WebService?
  • PHP nest variable in echoed string that contains a HTML tag in the end
  • Multiple Ajax request for PHP framework
  • Debug Info from Moodle Plugin
  • passing variables through page
  • Passing PHP $result data to Javascript
  • cakePHP File Download was not found or not readable
  • batch waiting until script finishes
  • PHP variables and anchors in URL
  • php eTag generation using php
  • How to check whether the array is an Integer or Not?
  • Is it possible to install Doctrine without PEAR or Composer? If so, how?
  • Call view script of (parent) Abstract controller Zend
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org