SQL 2012 :: Powershell Script To Verify Showplan Enabled For User?
May 18, 2015
I am looking for a sample PowerShell script that allows me to verify that showplan is enabled for a user on a SQL Server 2012 instance. Haven't figured out how to code it.
I was trying to review some query statistics and received the following message:
SHOWPLAN permission denied in database Test I gave the user permission by the following command: Grant showplan to user. I am curious as to how much perfomance does this effect? Is there an alternative? regards
i am using powershell to get the output..I am planning implement sorting to my output.below is the format I am writing my objects to html file.I want sort the object of lastrunoutocome field.
Hi, all! I'm really confused about how to run a query on the database to check to see the CustomerID filed value already exists in the database. If it’s true, I want to display a message: “Valid� the user to proceed with the next steps Else Display the customer number doesn’t exist in the database, and cancel. I tried all sorts of things and I just can't get it to do it. Hopefully you can help. Thank you
1) I can connect to SQL Server 2012 named instance from SSMS.
I can launch Power shell in any of the supported data contexts, for example from the named instance.
However when I try to run a query in Power Shell, I get the named pipes error.
2)I can also provide a connection string and connect to the SQL Server Instance form Windows PowerShell after launching SQLPS, the same as in the above. I can open the connection and verify its state, but trying to run a query results in the same error.
I also see that named pipes is enabled in the SQL Server Configuration Manager.
Some of this is the result of some ambiguity in the Windows User Account in Windows 8 computer. Some of this is documented in more detail here: [URL] .....
This link is not directly related to the above problem, but arises out of the ambiguity in the Username retrieval: [URL] ....
When I am in Visual Studio 2005, and I try to add an SQL database, I get the following error "generating user instances in sql server is disabled. use sp_configure user instances enabled to generate user instances." I am currently using SQL server 2005 Express. What do I need to do, to create an SQL database? Thanks in advance.
We have 15-20 report server environments including Dev/SIT/UAT/PROD/DR etc. so instead of configuring it on each servers, we would like a script to use with parameters.
After installing the SSRS 2012 package on each server with given instance and service account, I would like to configure the SSRS through script instead on running the Configuration manager RSConfigTool.exe manually.
we already have created the database beforehand using the scripts provided by WMI. do we need db_owner permission on msdb and master database to configure SSRS?
We have a server with a database with filestream enabled. The filestream data is in a filegroup with three files spread across 3 LUNs F:, G:, and H: each with a capacity of 1.8 TB.
The file stream containers in those three LUNs reference the same column in the same table.
The F: Drive has only 64 GB free space left. The H: However has around 700 GB free.
We are looking to move some filestream content from the container in F: to the container in H:.
I am aware that TDE protects data at Rest and not during communication or data in motion (UNLESS you use Encrypted communication channels using SSL certs etc). Hence I am thinking of doing data export from a TDE encrypted database to a database on the instance where TDE is not enabled or supported. I believe it works and need to take care of relationships between tables.The target database is hosted on SQL 2012 standard edition on which TDE is not supported.
I have a database that is the publisher in transactional replication and also part of an availability group. I have put the pertinent certificates on all of the involved servers, and it is encrypted on all servers and operated as expected. However, we are adding additional security for personal data and we have targeted columns in multiple tables for column encryption. I have a master key and certificates that are stored in the master database. Following an example where I am to create the database master key:
-- Create database Key USE encrypt_test; GO CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Password123'; GO
But when I try to create a certificate on the database:
-- Create self signed certificate USE encrypt_test; GO CREATE CERTIFICATE Certificate1 WITH SUBJECT = 'Protect Data'; GO
It get the following: Msg 15151, Level 16, State 1, Line 1 Cannot find the certificate 'Certificate1', because it does not exist or you do not have permission.
Can I add a database certificate to an already TDE enabled database and if not to I create the symmetric key through the certificate located on the master database? And how will that effect decrypting the column values in stored procedures and function on the user database?
My index reorganise maintenance plan fails partly due to the disabled indexes
Executing the query "ALTER INDEX [I_ModelSecurityCommon_RECID] ON [dbo]...
" failed with the following error: "Cannot perform the specified operation on disabled index 'I_ModelSecurityCommon_RECID' on table 'dbo. Model SecurityCommon'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
I don't want to delete the indexes as they are standard indexes that where on the DB from install.. any script that will reorganise all enabled indexes? and also to rebuild?
Our Sql server is not responding, So we restarted the server and modified one of the sp code. After that we are getting frequently every 2 min giving the below error
The queue 855365233 in database 9 has activation enabled and contains unlocked messages but no RECEIVE has been executed for 453199 seconds
I am trying to delete tables from data where the ModifiedDates older than 9 years in AdventureWorks2012 database . I get console notified that foreign keys are dropped but the delete statement is throwing errors. I am sure that somewhere the key constraints are not getting altered, but i'm not able to figure it out as i'm a relative beginner to T-SQL. The error and code:
The DELETE statement conflicted with the REFERENCE constraint "FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID". The conflict occurred in database "AdventureWorks2012", table "Sales.SalesOrderHeader [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null $option_drop = new-object Microsoft.SqlServer.Management.Smo.ScriptingOptions; $option_drop.ScriptDrops = $true;
I receive Error: 3967, Severity: 17, State: 1. Insufficient space in tempdb to hold row versions. We have 8 data files for temp db of 10210 GB size and given 10240 GB as max size.
As MS suggest to calculate the temp db file size and growth rate we need to monitor the perform counters Free Space in Tempdb (KB) and Version Store Size (KB) in the Transactions object.
basic formula: [Size of Version Store] = 2 * [Version store data generated per minute] * [Longest running time (minutes) of your transaction
My report disk utilizations says tempdb is full ? I thonk I need a shrink for the file .
Still I am confused in calculating the size , My perform counter gives me data as such
Free Space in tempdb (KB)              279938496 Version Generation rate (KB/s)          53681040 Version Cleanup rate (KB/s)      53422320 Version Store Size (KB)     258720 Version Store unit count      22 Version Store unit creation                     774 Version Store unit truncation        752
We are in plan to build a Monitoring tool using PowerShell and Performance Monitor which could monitor 10 to 20 servers. Do you have any reference of any existing tool using Performance Monitor to monitor the SQL Server and available for free? I didn't want to put some effort, if something is available already.
I have a scenario where a customer is going to be using Log Shipping to the DR site; however, we need to maintain the normal backup strategy on the current system. (i.e. Nightly Full, Every 6 Hour Differential and Hourly Transaction Log backup)I know how to setup Transaction Log Shipping and Fail-over to DR and backup but now the local backup strategy is going to be an issue. I use the [URL] .... maintenance solution currently.
Is it even possible to do regular backups locally keeping data integrity for your backup strategy with Transaction Log Shipping enabled?
I have a view in a database called PS_EMPLMT_SRCH_US and it joins around five tables. I have two databases which are identical structures including data. But when run one query ie "SELECT * FROM PS_EMPLMT_SRCH_US where EMPLID like '00918%' and OPRCLASS like 'ALLPANLS' ", response time is totally different even though both databases have same data and same indexes. When I looked at showplan and stats time, both are totally different and order of table fetch is totally different. Is there any idea why this difference? Any help would be appreciated.
Here is the show plan info: ------------------------------------------------------------------- GOOD Performance Query and plan -------------------------------------------------------------------
SELECT * FROM PS_EMPLMT_SRCH_US where EMPLID like '00918%' and OPRCLASS like 'ALLPANLS'
SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms. SQL Server parse and compile time: CPU time = 156 ms, elapsed time = 156 ms.
I´m wriing a small perl script that connects to SQL Server through ODBC, using DBI and DBD-ODBC modules.
I can get data from a query, but I cannot get the execution plan for it... instead, I got "[Microsoft][ODBC Driver Manager] Function sequence error".
Using Profiler, I can see both "set showplan_xml on" and my query as "SQL BatchCompleted" events on target database. The same happens when I use "set showplan_text on".
Is it possible to get an execution plan through ODBC?
I´m writing a small perl script that connects to SQL Server through ODBC, using DBI and DBD-ODBC modules.
I can get data from a query, but I cannot get the execution plan for it... instead, I got "[Microsoft][ODBC Driver Manager] Function sequence error".
Using Profiler, I can see both "set showplan_xml on" and my query as "SQL BatchCompleted" events on target database. The same happens when I use "set showplan_text on".
Is it possible to get an execution plan through ODBC?
I would like to know if there is a way to find out who changed a users roles/access WITHOUT using the audit function. For example, if a user account was created and given SA access then changed to read only, how can I find out who made that change? I tried searching for an answer, but kept getting no results. I'm thinking this may tie into the sys.sysusers view?
I am relatively new to sql developer. There is a new user that just joined our organization. I am trying to grant him the same direct grants privilege to the tables that an existing user has. The existing user has a ton of direct table access privileges and it will take days if I had to do each grant one by one like: grant select,insert,delete,update on 'table name' to 'user id'. Is there a way of copying or inserting an existing user's privilege and granting it to a new user.
I have an SSIS package built by another developer, and now that I'm running it under my login the passwords won't save. The solution and packages are setup with ProtectionLevel EncryptSensitiveWithUserKey, but how do I get the User Key to reset so I can now save passwords? I can re-enter them, but whenever I enter hte password and test it then click OK it still has the red arrow next to the connection as if there's an error. I can create new connections and those passwords save fine, but with 40-50 items in this package I hate the thought of having to go into each and change the connection.
I tried changing the package and solution to DontSaveSensitive then rebuilding and closing then reopening, I hoped there was some option to reset the User Key just as if I created the solution. If this option doesn't exist why?
Hi, I am trying to get performance data using powershell. When I run the command "get-wmiobject -list" I get classes like Win32_PerfRawData_MSSQLSQLEXPRESS1_MSSQLSQLEXPRESS1Locks. However when I run the command
get-wmiobject -query "select * from Win32_PerfRawData_MSSQLSQLEXPRESS1_MSSQLSQLEXPRESS1Locks" powershell gives me an error. Why is this happening? any help in this regard is appreciated.
I would get from scripting the replication out from SQL Server itself. However, there are a couple of things that are not showing up in the script,Adding the option to IncludeUninstallDistributor or UninstallDistributor doesn't appear to add any code to actually do that. i.e. the below code is never added.
/****** Uninstalling the server as a Distributor. Script Date: 10/1/2015 4:34:13 PM ******/ use master exec sp_dropdistributor @no_checks = 1, @ignore_distributor = 1 GO Also, adding the reverse for the create script generation, IncludeInstallDistributor or InstallDistributor, does not add the below code. use master exec sp_adddistributor @distributor = N'xxxxxx', @password = N'' GO
The purpose of the script is simply to script out all drop/create scripts for all publications and subscriptions, run the drop script, restore over the databases using backups of non-replicated databases, run the create replication script, and have it re-sync.
I would like to use powershell commands within my TSQL scripts. how to do that?
The reason is that up until now I have been using SQLCMD and XP_CMDSHELL to rename files before importing them into a database. Powershell is a better tool for this job.