I am a SQL Database Admin and curious about is it possible to check Application pool site status remotely from DB server?
Is there any way (e.g. SSIS package or SQL script) that I can get the result in table or file?
Thanks in advance
Execute SQL query in SQL server management studio as below :
SELECT DB_NAME(dbid), COUNT(dbid) AS NoOfConnections, loginame
FROM sys.sysprocesses
WHERE dbid > 0
GROUP BY dbid, loginame
Related
I would like to insert data from prod server to dev server for a particular table.
I am using insert into SQL query and fully qualified name. That is I am specifying server name, databsename, schema name and table name.
insert into ServerADev.[ING_DB].dbo.[Table1]
select *
from ServerAProd.[ING_DB].dbo.[Table1]
where ID = '08914'
ID is the column in Table1.
For above query I am getting an error:
Cannot find ServerAProd in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
When I EXEC sp_addlinkedserver #server='ServerAProd', I am getting:
User does not have permission to perform this action.
Do I need to make a request to DBA (database admin) to grant permission to perform this query?
You need to set up a linked server to query a foreign server.
So, either:
ServerAProd is not what you named the linked server
or
You didn't create a linked server yet. You can use the sp_addlinkedserver from the error message, or browse to "server objects" in the object explorer then right-click -> new on "Linked Servers". See the link above for more details.
For your edit... yes this requires permissions:
When using Transact-SQL statements, requires ALTER ANY LINKED SERVER permission on the server or membership in the setupadmin fixed server role. When using Management Studio requires CONTROL SERVER permission or membership in the sysadmin fixed server role.
1. create linked server for the dev server on production server,
2. use this openquery() to insert data, so that you can insert large data very quickly.
INSERT OPENQUERY (devservername, 'SELECT * FROM devservar_database..dev_server_table_name')
select * from production_table_database_name..production_table_table_name
I have a program where I need to create a user through SQL and give them access to a database. This program is run against SQL Server 2000. I could have sworn the SQL was working when I wrapped up at the end of the day yesterday but it's not working today and I'm pulling my hair out trying to make it work.
use master
exec sp_addlogin #loginame='newLogin', #passwd='password', #defdb='theDB'
use theDB
exec sp_grantdbaccess newLogin, newLogin
grant all to newLogin
After running the SQL statements as "sa" I log in as the new user and try to select from any of the tables in the database and get
SELECT permission denied on object 'XXXX', database 'YYYY', owner 'dbo'
What am I missing?
Adding the user as a db_owner for the specific database seems to do the trick.
I have a group called kwr-fs-dws-sqladm (Active Directory/Exchange) and there are two users in this group.
This group will go to all sql server and instances. I have access to windows server 2008 as admin.
How can I add that group in all 60 SQL Servers and 200 Instances?
i.e. kwr-fs-dws-sqladm - user as sysadmin -.
Use [Master]
CREATE LOGIN [DOMAIN\kwr-fs-fws-sqladm] FROM WINDOWS;
EXEC sp_addsrvrolemember 'DOMAIN\kwr-fs-fws-sqladm', 'sysadmin';
Execute on each server, you will want to check out the CREATE LOGIN syntax for extra options.
I've never managed that many SQL servers, i'd assume there is a way of executing on all. One way is to add each server to a server group in SSMS, then you can right click that group and create a new query which will execute on each server.
Given the remote server 'Production' (currently accessible via an IP) and the local database 'Development', how can I run an INSERT into 'Development' from 'Production' using T-SQL?
I'm using MS SQL 2005 and the table structures are a lot different between the two databases hence the need for me to manually write some migration scripts.
UPDATE:
T-SQL really isn't my bag. I've tried the following (not knowing what I'm doing):
EXEC sp_addlinkedserver
#server = N'20.0.0.1\SQLEXPRESS',
#srvproduct=N'SQL Server' ;
GO
EXEC sp_addlinkedsrvlogin '20.0.0.1\SQLEXPRESS', 'false',
'Domain\Administrator', 'sa', 'saPassword'
SELECT * FROM [20.0.0.1\SQLEXPRESS].[DatabaseName].[dbo].[Table]
And I get the error:
Login failed for user ''. The user is
not associated with a trusted SQL
Server connection.
create a linked server and then use 4 part notation
insert table
select <column names>
from LinkedserverName.DatabaseName.SchemaName.TableName
you can also use OPENROWSET
example
insert table
SELECT a.*
FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;',
'SELECT GroupName, Name, DepartmentID
FROM AdventureWorks2008R2.HumanResources.Department
ORDER BY GroupName, Name') AS a;
try this to create the login
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'20.0.0.1\SQLEXPRESS',
#useself=N'False',
#locallogin=NULL,
#rmtuser=N'sa',
#rmtpassword='saPassword'
You can define the PROD Server as Linked Server to the DEV box and then access it.
However I think it would be easier to get a backup from PROD Box and Restore it to DEV or use SSIS for Schema Import.
Look into the RedGate tools, esp. SQL Data Compare. If that's not an option you should look at OPENDATASOURCE or OPENROWSET to access the remote database.
Well you can use a linked server and then use the 4 part names for objects (See BOL for how to set up a linked server)
Or you could use SSIS to set up the data migrations and connect to the remote server
Or you could use OPENROWSET
I'd probably use SSIS, but I'm already familiar with it.
Use SSMS. Right click on the target DB and select "Tasks", "Import Data". You will be able to preview the data and make conversions visually. Save the package in SSIS or run it now.
While I'm trying to detach a database through Enterprise Manager, it shows the no. of users accessing the database and it didn't allow us to detach without clearing the database connection.
Well, I want to know whether the result (no. of users connecting a particular database) could be obtained through a SQL query? If yes, how ?
Happiness Always
BKR Sivaprakash
This will give you proper results. Add your database name in the query -
select spid, status, loginame,
hostname, blocked, db_name(dbid) as databasename, cmd
from master..sysprocesses
where db_name(dbid) like '%<database_name>%'
and spid > 50
This will include logins from SQL Agent. Note that the
same user can be using multiple connections from the same application,
and thus be counted more than once.
EXEC SP_WHO
or
EXEC SP_WHO2
maybe (think this might be SQL Server 2005 upwards):
SELECT COUNT(*) AS ConnectionCount,
CASE WHEN is_user_process =1 THEN 'UserProcess' ELSE 'System Process' END
FROM sys.dm_exec_sessions
GROUP BY is_user_process