SQL Server 2012 Linked Server Connection Issue - sql

I have a local SQL Server 2012, and a vendor has a remote SQL Server 2012 setup for us with a read only SQL user. The vendor will do nothing except provide this read only login. I can login and query with remote credentials all day long. But, when connected to my instance, I can't query the vendor instance. I need to query and run jobs from my server, but can't.
Here's some info on what I can and can't do:
Login with their credentials and run queries:
Server: Some.I.P.Address\SomeName
U: ReadOnlyUser
P: ThePassword
I Created a linked server with my local logins and the above remote user which will pass a connection test.
From my server I can query a remote system table, but not the remote user tables:
Meaning I CAN NOT do this:
Select top 1 * from [Some.I.P.Address\SomeName].DateBaseName.ReadOnlyUser.[TableName]
But I CAN do this:
SELECT top 1 * FROM [Some.I.P.Address\SomeName].master.sys.Servers
How come I can connect directly to the remote instance and run queries, but when I am connected to my server I can only query the system tables?
It gives me this error, but A) the table does exist, and B) the user does have permissions because I can connect directly with the same credentials that pass the linked server connection test and run a query on that table.:
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI11" for linked server "[Some.I.P.Address\SomeName]" does not contain the table ""DateBaseName"."ReadOnlyUser"."TableName"". The table either does not exist or the current user does not have permissions on that table.

Related

Unable to view one database

I am new to an organization, and there was a SQL Server link set up before I started between to servers. There are 12 databases on the linked server, and I can access all of them but one. For example, I run [SELECT * FROM [SERVER].Database.dbo.table1] and get a result set. And this is the case for all databases except 1. I run [SELECT * FROM [SERVER].Database2.dbo.table1] on that one and get "The OLE DB provider "SQLNCLI11" for linked server "SERVER" does not contain the table ""Database2"."dbo"."Table1"". The table either does not exist or the current user does not have permissions on that table. The table exists, and I am able to select from it on the originating server with no issues. I am logging in with windows authentication. Any ideas?
I have verified that I have the same database permissions on 1 that I can reference as the one I cannot.

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

Execute remote SQL script with linked server

I've got 2 servers in a workgroup called "workgroup".
Server A is W2012R2 with SQL Server 2012.
Server B is W2012R2 with other application. SQLCMD Utility has been installed on server B.
I'm using local account, SQL service is start by local account. I can connect to the SQL server from B to A. I can launch query without difficulty. When I launch my SQL script, I get the following error:
E:\Batch\Script>sqlcmd -S YMSQL01 -i test.sql
Changed database context to 'PROD'.
Msg 7399, Level 16, State 1,
Server YMSQL01, Procedure V_C_Prod, Line 3 The OLE DB provider
"Microsoft.ACE.OLEDB.12.0" for linked server "C_PROD" reported an
error. The provider did not give any information about the error.
Msg 7303, Level 16, State 1, Server YMSQL01, Procedure V_C_Prod, Line 3
Cannot initialize the data source object of OLE DB provider
"Microsoft.ACE.OLEDB .12.0" for linked server "C_PROD".
As you can see, it seems that I cannot query on a view. This view is from a linked server which is connected to an Excel file (located on server B). I have installed the same ODBC driver on server B but I get the same error.
My SQL script:
Use PROD
Go
Merge dbo.conc AS t
using V_C_Prod as s
ON (t.CodeComptable=s.[Code Comptable])
WHEN MATCHED THEN UPDATE SET
t.[Marque]=s.[Marque]
,t.[CodeHolding] = s.[Code HOLDING]
,t.[Email1]=s.[Email Principal]
,t.[CP]=s.[CP]
,t.[Ville]=s.[Ville]
WHEN NOT MATCHED
THEN INSERT VALUES (
s.[Marque]
,s.[Code HOLDING]
,s.[Code Comptable]
,s.[Email Principal]
,s.[CP]
,s.[Ville];
Go
How can I solve this issue?

sql server base tables

I use SQL Server 2012.
How can select from sql server system base table such as below tables.
sys.sysschobjs
sys.sysbinobjs
sys.sysclsobjs
When I get query from base system table such as below query. get following error.
select * from sys.sysschobjs
Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.sysschobjs'.
It is doable if you used a "Database Engine Query", and an administrator user.
To do so, after you open the SQL Management Studio:
Click File Menu, "New" sub menu, and select "Database Engine Query".
In the server name, write "Admin:" before your server name (eg., if your server name is "localhost", then the full server name to be written is "admin:localhost")
Then write your credentials (for administrative account).
N.B.: Make sure that there are no other administrator logged in to the Database Engine Query other than you (I believe it is a single access point)
For more information:
http://technet.microsoft.com/en-us/library/ms178068(v=sql.105).aspx
http://zarez.net/?p=774
To query this system base tables needs a Dedicated Administrator Console (DAC).
First, connect to your database using the DAC. To do this from SQL
Server Management Studio, go to File -> New -> Database Engine Query.
Put ADMIN: in front of your instance name and click Connect.
Change to the your database using the USE [mydb]
Now you can query
select * from sys.sysschobjs
See this post for further info on this:
http://www.hackingsqlserver.com/
https://sqlblog.org/2011/11/08/t-sql-tuesday-24-dude-wheres-the-rest-of-my-procedure

How do you setup a linked server to an Oracle database on SQL 2000/2005?

I am able to create and execute a DTS package that copies tables from a remote Oracle database to a local SQL server, but want to setup the connection to the Oracle database as a linked server.
The DTS package currently uses the Microsoft OLE DB Provider for Oracle with the following properties:
Data Source: SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.3.42)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=acc)));uid=*UserName*;pwd=*UserPassword*;
Password: UserPassword
User ID: UserName
Allow saving password: true
How do I go about setting a linked server to an Oracle database using the data source defined above?
I was able to setup a linked server to a remote Oracle database, which ended up being a multi-step process:
Install Oracle ODBC drivers on SQL Server.
Create System DSN to Oracle database on SQL Server.
Create linked server on SQL server using System DSN.
Step 1: Install Oracle ODBC drivers on server
a. Download the necessary Oracle Instant Client packages: Basic, ODBC, and SQL*Plus (optional)
b. Unzip the packages to a local directory on the SQL server, typically C:\Oracle. This should result in a [directory] like C:\Oracle\instantclient_10_2, which will be the value of [directory] referenced in the rest of this answer.
c. Create a text file named tnsnames.ora within the instant client [directory] that contains the following:
OracleTnsName =
(
DESCRIPTION=
(
ADDRESS = (PROTOCOL=TCP)(HOST=10.1.3.42)(PORT=1521)
)
(
CONNECT_DATA = (SERVICE_NAME=acc)
)
)
Note: Actual HOST, PORT, and SERVICE_NAME will vary based on Oracle server you are establishing a connection to. This information can often be found using the Oracle network client tools under the listeners.
The OracleTnsName can be any name you want to assign to the Oracle data source, and will be used when setting up the system DSN. You can also use the syntax above to define multiple TNS names in the same tnsnames.ora file if desired.
d. Add the [directory] to the system PATH environment variable.
e. Create a new system environment variable named TNS_Admin that has a value of [directory]
f. Execute the [directory]\odbc_install.exe utility to install the Oracle ODBC drivers.
g. It is recommended that you reboot the SQL server, but may not be necessary. Also, you may want to grant security permissions to this directory for the SQL server and SQL agent user identities.
Step 2: Create a System DNS that uses the Oracle ODBC driver
a. Open the ODBC Data Source Administrator tool. [ Administrative Tools --> Data Sources (ODBC) ]
b. Select the System DSN tab and then select the Add button.
c. In the drivers list, select Oracle in instantclient {version}. (e.g. 'Oracle in instantclient 10_2') and then select Finish button.
d. Specify the following:
Data Source Name: {System DSN Name}
Description: {leave blank/empty}
TNS Service Name: should have the OracleTnsName you defined in the tnsnames.ora file listed, select it as the value.
User ID: {Oracle user name}
e. Select Test Connection button. You should be prompted to provide the {Oracle user password}. If all goes well the test will succeed.
Step 3: Create linked server in SQL to the Oracle database
Open a query window in SQL server and execute the following:
EXEC sp_addlinkedserver
#server = '{Linked Server Name}'
,#srvproduct = '{System DSN Name}'
,#provider = 'MSDASQL'
,#datasrc = '{System DSN Name}'
EXEC sp_addlinkedsrvlogin
#rmtsrvname = '{Linked Server Name}'
,#useself = 'False'
,#locallogin = NULL
,#rmtuser = '{Oracle User Name}'
,#rmtpassword = '{Oracle User Password}'
Note: The {Linked Server Name} can be anything you want to use when referencing the Oracle server, but the {System DNS Name} must match the name of the system DSN you created previously.
The {Oracle User Name} should be the same as the User ID used by the system DSN, and the {Oracle User Password} should be the same as you used to successfully test the ODBC connection. See KB 280106 for information on troubleshooting Oracle linked server issues.
Querying the Oracle linked server
You may use OPENQUERY to execute pass-through queries on the Oracle linked server, but be aware that for very large recordsets you may receive a ORA-01652 error message if you specify a ORDER BY clause in the pass-through query. Moving the ORDER BY clause from the pass-through query to the outer select statement solved this issue for me.
I had the same problem. I was on the phone with Microsoft for hours, and they did not have a solution. None of those "connection timeout" settings helped me.
To resolve it, I created a DTS job that runs a proc which only updates the time on one row, in one column, every two minutes. Then I setup a replication between SQL Server and Oracle, scheduled to replicate that single cell change, from SQL to Oracle, every 3 minutes. It keeps the connection alive!