MS SQL data to MS SQL by connection string - sql

Good day I have
Server 1-
Server=10.000.00.01;
Database=DBNAMESOURCE
Table - tablename
;User Id=username;
Password=***;
And
Server 2 –
server=100.00.100.00;
database=dbnamedest;
table – tablename
I need get data from table on server1 to table on server2 To server 1 I connecting by different user as my current userlogin.
Do you have idea how I can retrieve data from server to server by different user… I try setup string like this but not work.. Usually I use this type of string but I have my user login in users section on the other servers.
I read https://www.connectionstrings.com/sql-server-2012/ but I can not fit.
/TABLESOURCE:username.tablename /SOURCETYPE:0 /TABLEDEST:tablename /DESTINATIONTYPE:0 /TRUNCATE:1 /PROC:1 /CSPARAMDB:server=100.00.100.00;database=dbnamedest;trusted_connection=true /CSSOURCE:“Server=10.000.00.01;Database=DBNAMESOURCE;User Id=username;Password=***;trusted_connection=true”/CSDEST:server=100.00.100.00;database=dbnamedest;trusted_connection=true /LDB:NO

Related

SQL Server update two different server by trigger

I have two SQL Server
1st - 10.101.102.133
2nd - 10.101.102.155
Both having the different database with different names and fields.
My application will update in the 1st server.
Can I actually configure the 1st server that once it received update query, it will update in 2nd server as well?
I want to insert data from 1st server to 2nd server by using trigger. when my Application insert data in a table in 1st server database a trigger will fire (insert trigger). and it pass the data in 2nd server by its user id and password.
How I write the script of this trigger?
Solved here: Selecting data from two different servers in SQL Server
You can use sp_addlinkedserver or Linked Servers approach.
Using sp_addlinkedserver would be something like this once you have set up the linked server:
select
*
from
LocalTable,
[OtherServerName].[OtherDB].[dbo].[OtherTable]

How to transfer/migrate tables with schema from SQL Server to Oracle?

I have tables from my SQL Server 2008 R2 that have a schema. I manage to transfer some tables to sql developer but the tables with schema did't transfer. How to do?.
You can use DTS (Data Transformation Service) at SQL Server Side or you can configure Gateway at oracle side. To Use DTS you should have oracle client on the machine where you are executing DTS.
DTS will ask you for source and destination and it's credential. So as you need to migrate from SQL to Oracle. In source tab select "Microsoft OLEDB Provide for SQL Server" as Data Source, Put IP Address / Server Name in Server Name DDown. If you have Window Authentication then let it be and select database and go to Next. If you have login ID and Password, select SQL Server Authentication put Login Id and Password, Select you database and then click on Next button.
In destination Tab select "Microsoft OLEDB Provider for Oracle", then click on Properties. And put TNSName into Server Name (You configured using NETCA in Oracle Client on the machine) and LoginId and Password.
After you get connected it will display to use query or complete table, you just click on next without selecting any option.
Then it will display all tables from source, select the table you need to migrate then click on next till finish.
For Gateway configuration, take help from this link.
https://docs.oracle.com/cd/B28359_01/gateways.111/b31043/conf_sql.htm
Thanks

Run a Sql Query on multiple Servers and each server has different databases(database name is diff on each server) with same tables

Run a Sql Server Query on multiple Servers and each server has different databases(database name is diff on each server) with same tables
In the management studio, you can register multiple servers into one group. Then you can run query on the group.
In SSMS open Registered Servers and create a New Server Group under Local Server Groups.
Under this group create New Server Registration for each server you wish to query. If the DB names are different ensure to set a default for each in the properties. You can register a server/instance multiple times with different default DBs.
Now go back to the Group you created in the first step, right click and select New Query. A new query window will open and any query you run will be executed on each server in the group. The results are presented in a single data set with an extra column name indicating which server the record came from. If you use the status bar you will note the server name is replaced with multiple.

Connect VB with SQL (Local + unknown database name)

Basically I want to know if it is possible to connect my VB app with SQL server on the same Computer (Local) and interrogate it for a list of database names.
I just want to know if that is possible.
sqlConn.ConnectionString = Data Source=local;Initial Catalog=unknownDatabase;User Id=knownUsername;Password=knownPassword;"
Fill DataBase Names to Drop Down
User Selects DB Name
Change Connection to now Known DatabaseName
Of course it is possible.. You can create a connection to a local SQL instance the same way you'd create a connection to a remote one.
Then to get a list of the databases on the server, execute "SELECT Name FROM master.sys.databases"

LINKED Server does not return all rows

This is a little strange for me. I have script like following
DECLARE #maxCustId INT
SELECT #maxCustId = MAX(CustomerId) FROM Customers
SELECT * INTO #temp FROM linkserver.DB.dbo.Customers where CustomerId > #maxCustId
-- Copy records to local db Custome table
DROP TABLE #temp
But sometimes #temp does not fetch all records from linked sever.
Like I had Max CustomerId = 1138 in my local db and when I run above script my temp table (which fetch records from linked server) misses CustoemrIds 1140, 1141. Linked server has customers upto 1160. #temp table has records upto 1160 but misses two records i.e. 1140, 1141
I run that script again and again and on 4th attempt the record 1141 added in #temp table but record 1140 was still missing.
I then put following query on local server to check record in linked server
SELECT * FROM linkserver.DB.dbo.Customers where CustomerId = 1140
Above query return no records.
To verify this I went to linked server and wrote same query on server from where I have created LINKED server.
-- This is the server which I am using as linked server in my local server
SELECT * FROM Customers where CustomerId = 1140
Custoemr 1140 was in db, which I was sure that it would be there but I run above script to verify it.
I come back to my local server and run this query
SELECT * FROM linkserver.DB.dbo.Customers where CustomerId = 1140
This time my linked server returns customer 1140 which it was not returning earlier.
I run the whole query again and now my #temp table has all records.
I am so confused that why first time linked server did not return all records.
This is sample from a long procedure which copy records from linked server to local server and because of this reason my local db has less records than linked server db.
Linked server: SQL Server 2005 Standard with SP2
Local Server: SQL Server 2008 Web Edition with SP2
Provider: SQL Native Client 10
Linked server security options:
Be made using the securing context
Remote Login
With Passowrd
login user details:
Server Roles: public and sysadmin
User Mappings: sa is not mapped with
db I query.
Linked server db updated frequently
No NOLOCK at any point in query
Any help.
I have seen similar behaviour with linked servers (although usually Oracle not SQL Server) and the problem was traced to the driver being used for the linked server.
I see you have SQL Native Client 10 as the provider, could you try using Microsoft OLE DB Provider for SQL Server instead and seeing if it makes a difference?
Also would be curious to know if you have the same problem when you use OpenQuery instead of the four-part naming convention:
SELECT * FROM OpenQuery(linkserver,'SELECT * FROM Customers where CustomerId = 1140')
IIRC, that should be faster, anyway... I believe that would force it to take care of the "where" part on the linked server and only return the appropriate values as opposed to returning the whole dataset and doing the filterin' on the destination side. Of course, I'm also pretty sure I saw a UFO at my Granny's house when I was eight, so take my wisdom with a grain of salt.