Transact-SQL

System Center 2012 SP1 Operations Manager: Datawarehouse configuration failed to install

Posted by on Feb 19, 2013 in SC Operations Manager, SQL Server, Transact-SQL | 1 comment

System Center 2012 SP1 Operations Manager: Datawarehouse configuration failed to install

While installing Microsoft System Center 2012 SP1 Operations Manager I got following error: In the log I could see that Setup could not create the Datawarehouse database: EXEC(@sql);: Threw Exception.Type: System.Data.SqlClient.SqlException, Exception Error Code: 0x80131904, Exception.Message: CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file ‘E:\SQL\Data.mdf’. CREATE DATABASE failed. Some file names listed could not be created. Check related errors. I have a standalone SQL 2012 SP1 server (SQL) and a Windows...

Read More

Cannot insert duplicate key error while upgrading SCCM 2012 to SP1

Posted by on Feb 5, 2013 in SC Configuration Manager, SQL Server, Transact-SQL | 1 comment

Cannot insert duplicate key error while upgrading SCCM 2012 to SP1

The following error occurred during SP1 update of Microsoft System Center 2012 Configuration Manager: ERROR: SQL Server error: [23000][2627][Microsoft][SQL Server Native Client 11.0][SQL Server]Violation of PRIMARY KEY constraint ‘CollectionQueryRuleTables_PK’. Cannot insert duplicate key in object ‘dbo.CollectionQueryRuleTables’. The duplicate key value is (16777228, 1, vSMS_R_System). Configuration Manager Setup 05.02.2013 09:12:18 4084 (0x0FF4) The easiest way would be to delete the corresponding rows from CollectionQueryRuleTables table in your SCCM database. This...

Read More

SQL Server 2012: Always On and SQL Server authentication

Posted by on Sep 4, 2012 in SQL Server, Transact-SQL | 1 comment

SQL Server 2012: Always On and SQL Server authentication

Here is just a small problem I experienced while adding databases with SQL Server authentication enabled (used for some php websites) to an availability group. Steps I took to add the databases: Add all logins to the secondary server (SQL Management Studio > Security > Logins > Create login) Add database to availability group (Always On High Availability > Availability Groups > desired group > Add Database) So the operation was successful and all databases were synchronized. Now I did a manual failover to the second node. But the php application was not able to login...

Read More

How to (re-)set identity column value in SQL Server?

Posted by on Mar 2, 2011 in SQL Server, Transact-SQL | 0 comments

When you use identity columns in SQL server you may have recognized that when deleting all table data your identity value stays at its latest position. Sometimes this is useful, sometimes it is not. Then you need to set this value to your preferred starting point. Another scenario would be that you need to start with a special position in a new table for example to meet naming conventions. All you need is the DBCC CHECKIDENT command. First you may want to know the value your identity column has at the moment: DBCC CHECKIDENT ('tablename', NORESEED) If you want to set the identity value to...

Read More

How to display active connections and running queries in SQL Server?

Posted by on Nov 6, 2010 in SQL Server, Transact-SQL | 0 comments

This query shows all queries executed at the moment, the session id, status, used cpu time and the execution duration SELECT st.text, r.session_id, r.status, r.command, r.cpu_time, r.total_elapsed_time FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS st The following query shows the number of connections a user has with a database SELECT db_name(dbid) as DatabaseName, count(dbid) as NoOfConnections, loginame as LoginName FROM sys.sysprocesses WHERE dbid > 0 GROUP BY dbid, loginame

Read More