sql server base tables - sql

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

Related

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

SQL Server 2012 Linked Server Connection Issue

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.

Microsoft SQL Server, Error 916

I'm using Microsoft SQL Server 2012 Management Studio Express. I have detached one of my databases (it was in my office server) and .mdf and .ldf files are saved to MSSQL folder (on my local server). While I was detaching the database it was saying that with my connections (hopefully the server) cannot detach the database. Then I selected the drop connections option in the detach mode.
Now when I try to attach the database it doesn't allow me to attach. When I click the add button doesn't give me the option to browse my folder. Below error message is showing.
Failed to retrieve data for this request.(Microsoft.SqlServer.Management.Sdk.Sfc)
Additional information:
An exception occurred while executing a Transact-SQL statement or batch.(Microsoft SQL server. connectionInfo).
The server principal "my username" is not able to access the database "model" under the current security context.(Microsoft SQL server, Error:916).
What should I do? Please help me.
To resolve the issue... follow the given steps.
(1) Start sqlserver and login
(2) Press "F7" or click on "View->Object Explorer Details" to open Object Explorer Details window.
(3) You will see there column header.. like "Name", "Policy Health State", "Recovery Model", "Collation" etc.
(4) Right click on the header and unselect the "Collation".
(5) Now refresh the database folder. You will get all database list.
It's not a problem with the actual attach statement, but rather with setting up the wizard UI (which is a shame IMO). Use T-SQL to attach the database instead:
create database MyDatabase
on
(filename = 'c:\Data\mydatabase_data.mdf'),
(filename = 'c:\Data\mydatabase_log.ldf')
for attach;
You'd be better off to use T-SQL all the time instead of SSMS wizards. Or use wizard to script out the action and execute in a query window.
Also, check what's the problem with the permissions on model. Use this query to see if there's any DENY:
use model;
go
select
user_name(p.grantee_principal_id),
dp.principal_id,
dp.type_desc as principal_type_desc,
p.class_desc,
object_name(p.major_id) as object_name,
p.permission_name,
p.state_desc as permission_state_desc
from sys.database_permissions p
inner join sys.database_principals dp
on p.grantee_principal_id = dp.principal_id
where p.state_desc = 'DENY'

How to retrieve records from server database into local database

I have a little problem. I want to create a query in my local database (tijdsregistratie.mdf) to retrieve rows from my server database (IT Solutions Develop.dbo) on server itshou-dev03\sql2008.
But I don't know how to connect to the server database. I tried it like this :
select TOP 10 * from [IT Solutions Develop].dbo.[IT Solutions BVBA$Planning]
.. but it gives me this error :
Invalid object name 'IT Solutions Develop.dbo.IT Solutions
BVBA$Planning'.
One way is to link the servers:
http://msdn.microsoft.com/en-us/library/ms188279.aspx?ppud=4
You can also define linked servers by using SQL Server Management
Studio. In the Object Explorer, right-click Server Objects, select
New, and select Linked Server. You can delete a linked server
definition by right-clicking the linked server name and selecting
Delete.
This is the process by which you tell SQL Server where another server is and how to connect to it. You can do this in SQL Server Management Studio or in T-SQL. You can then refer to the linked server by a four part name (similar to what is in your question):
[LinkedServerName].[Database].[Schema].[Object]

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!