How to: Get all the information regarding your SQL server installed

When running the following script, will get you a verbose of the SQL server installed. This will get you the Service Pack number, version and other information which includes Product Level and other interesting stuff.

Note: if you would like to get a simplified information on the SQL server simply run the SELECT @@VERSION on your SQL while using the Master database, but if you want to know more in detail, use the script below.

SELECT @@VERSION
GO

SELECT SERVERPROPERTY('ProductVersion') 'Version', SERVERPROPERTY ('ProductLevel') 'Service Pack', SERVERPROPERTY ('Edition') 'Edition'
GO

-- Stored procedure, documented in Books Online, that returns numerous key / value pairs including version information.
-- There doesn't seem to be a correlation between the key names here and SERVERPROPERTY values;
-- for example, 'ProductVersion' is returned by xp_msver, but 'ProductLevel' is not.
xp_msver
GO

-- Stored procedure, documented in Books Online, that returns numerous key / value pairs including version information.
-- For SQL Server 2008, DBMS_VER returns "Microsoft SQL Server Yukon - 10.0.1600".
sp_server_info
GO

-- Stored procedure, not documented in Books Online, that returns the version string.
sp_MSgetversion
GO

-- @@MicrosoftVersion returns a decimal value which, when converted to varbinary, yields (for example) 0x09000FC3.
-- Enter "convert 0x0FC3 to decimal" in Google, and the result is 4035. Thus the overall MicrosoftVersion is 09.00.4035.
SELECT CONVERT(VARBINARY, @@MicrosoftVersion)
GO

-- get version info from the registry (SQL 2005 key names - keys may vary)
xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup\', @value_name='Version'
GO
xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup\', @value_name='Edition'
GO
xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup\', @value_name='SP'
GO

-- get version info from the registry (SQL 2008 key names - keys may vary)
xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\Setup\', @value_name='Version'
GO
xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\Setup\', @value_name='Edition'
GO
xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\Setup\', @value_name='SP'
GO

How to: Find users in SQL having DB Owner role

Find members of db_owners in all databasesThis script is aim to provide all members of the db_owner database role in all databases in an instance. It
The following code returns the role name and the member name filtered for the db_owner database

This script is aim to provide all members of the db_owner database role in all databases in an instance. It uses sp_MSForEachDb with a custom script using sys.database_principals DMV. The following code returns the role name and the member name filtered for the db_owner database role.

exec sp_msForEachDb ' use [?]
select db_name() as [database_name], r.[name] as [role], p.[name] as [member] from
sys.database_role_members m
join
sys.database_principals r on m.role_principal_id = r.principal_id
join
sys.database_principals p on m.member_principal_id = p.principal_id
where
r.name = ''db_owner'''

How to: Execute SQL stored procedures using command line

Often when having SQL Express Editions installation I would like to schedule and execute stored procedures. Using Express editions you cannot make use of the SQL Agent, but you can run them manually using a batch file and using the SQLCMD.EXE file as below

SQLCMD /Q "USE mydb; EXEC mystoredprocedure"

This will use the mydb that you specify and run the mystoredprocedure. You can also use the > filename.txt to make the job log.

Fix: Insufficient Access Rights on Lync when adding new user

When adding a new Lync enabled user in the Lync Control Panel, you may have the following error message.

Active Directory operation failed on “DC01.MYDOMAIN.COM". You cannot retry this operation: “Insufficient access rights to perform the operation 00002098, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0″.

This is due to permissions on the Active Directory. Although you may have full Entrprise access, you will still fail to add new users. This can be fixes by below.

Open Active Directory Users and Computers
Click View and Selct Advanced Features
Right Click and select Properties on the users that you cannot add to Lync
Select Security and click Advanced.
Tick Include inheritable permissions from this object’s parent
Click OK and Click OK

Try to add the user again… ClickApu, it works.

Fix: Unknown error when trying to backup Edge Server with Yosemite

Backing up an Edge server with Yosemite you might get the error “Unkown Error“. This being because it will think that it’s an Exchange server and it will fail to find the mailbox.

On Edge server and right click on the Yosemite application link and Open File Location. Under folder config edit the ytdetect file using Wordpad.

Enter a semicolon (;) in front of the code as below.

;ods.6=Microsoft Exchange Server Agent,exw

[wns.v6.x86_64.primary]
;ods.1=Microsoft Exchange Server Mailbox Agent,exm

Restart services of Yosemite. Swish, there it’s fixed.

Fix: Cannot open database when publishing topology on Lync

When setting up the topology using the topology builder on the Lync server, you may get the below error.

Error: An error occurred: "Microsoft.Rtc.Common.Data.SqlConnectionException" "Cannot open database "xds" requested by the login. The login failed.
Login failed for user 'MYDOMAIN\Administrator'."

Although your credentials are correct, the issue is a known bug if you are using Microsoft SQL 2008 R2. This may be fixed by installing the Microsoft SQL 2008 R2 SP 2.

Another option would also be to check the user in the error as it must have sysadmin role in the SQL server security.

Also you might need to check if you have the installed SQL Server Backward Compatibility. This is a requirment.

Fix: InetPub Folder consuming a lot of storage on Windows Server SBS 2011

The other day I was having a problem with a lot of space being consumed in the C Drive on a Windows 2008 SBS or Windows 2011 SBS version. I have noticed that the InetPub log files were taking more than 50GB of space. Now, there is an automatic way to delete these log and have a breath of fresh space. You can either use the below script to run it manually or set it up in a Scheduled task. This will stop the services and clear the logs… Swish, there it’s fixed. Enjoy.

@ECHO OFF
CLS
ECHO ** STOP IIS SERVICE **
NET STOP "TSGateway"
NET STOP "W3SVC"
ECHO ** DELETE OLD LOGS **
Forfiles.exe /P "C:\inetpub\logs\LogFiles\W3SVC1" /M *.log /D -5 /C "Cmd.exe /C del @path"
ECHO ** START IIS SERVICE **
NET START "W3SVC"
NET START "TSGateway"

How to: Reset Blackberry device from command line

Sometimes I would have such devices with no access to their interface on the phone to go through the normal procedure and reset or wipe the phone to factory settings. So what should you do?

Firstly install the Blackberry Desktop Software which can be downloaded from the Blackberry site.

Open command line and make sure that you run it as Administrator
For 32bit browse to folder C:\Program Files\Common Files\Research In Motion\Apploader
For 64bit browse to folder C:\Program Files (x86)\Common Files\Research In Motion\Apploader
Type loader.exe /resettofactory and press Enter

Wait some time to finish. The window will close and the phone will restart to start the wipe procedure. Swish, there it’s fixed.

Fix: Exchange 2010 blank page when launching OWA

When using OWA and launching the browser, you will get no error and just a blank page. You will also notice the URL changes to:

https://mydomain.local/owa/auth/logon.aspx?url=https://mydomain.local/owa/&reason=0. No errors on IIS or Exchange.

This can be fixed by running the following lines in the Exchange Management Console in Powershell.

Import-Module ServerManager

and

Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -Restart

Re-open OWA into a new browser window and Swing! it’s Alive!

Fix: Exchange 2010 error when trying to log into OWA or ECP using Administrator only

After a fresh new installation in an already existent domain setup, when I tried to access the OWA (Outlook Web Access) or ECP (Exchange Control Panel) using the Domain\Administrator only (in my case). I got the below error:

A problem occurred while trying to use your mailbox. Please contact technical support for your organization.

When you click on More Details on the page, you will get:

Request
Url: https://mail.mydomain.local:443/owa/lang.owa
User host address: 10.1.1.1
User: User's Name
EX Address: /o=DOMAIN/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=administrator
SMTP Address: administrator@mydomain.local
OWA version: 14.0.694.0
Exception
Exception type: Microsoft.Exchange.Data.Storage.StoragePermanentException
Exception message: There was a problem accessing Active Directory. Check your network connections and try again.

Well, before you start tearing you hair, there is a simple fix for this. The problem is just security and can be fixed by the following steps.

Open Active Directory Users and Computers
Click on View and select Advanced Features
Find the user, right click and select Properties
Click on the Security tab and click on the Advanced button
Make sure that the Include Inheritibale Permissions checkbox is ticked

Open a new browser window and try to log in again. Swing! it lives! Thou in my case the issue was with just the administrator, it can be applicable to all the users.