Monday, March 26, 2018

Select = date without timestamp with sql

you may have a data for date column with timestamp
eg: 2018-03-26 13:40:22.470

let's say you need to check the date eg: 2018-03-26

Then you need to take part of the date string. you have various options, here i use convert()

 select count(*)
  -- convert(varchar(10),LastErrorOccurredDate,120)
 from Mytable (nolock)
 where convert(varchar(10),LastErrorOccurredDate,120) ='2018-03-26'

Thursday, March 22, 2018

Extracting list of windows services and their status to a text file

Below will extract details of windows services to a text file

Get-Service | Export-Csv -path "C:\Services\services.csv"

With below you can retrieve the running windows services list

Get-Service | where {$_.Status -eq "Running"} | Export-Csv -path "C:\Service\services.csv"

Friday, January 26, 2018

Error in creating Microsoft SQL server connection

Error:
Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library

This is the basic error and this will have a full stack trace.
When creating database connection, you must have enabled the "integratedSecurity=true".
This will enable LDAP users to access the database.

Solution :



1.goto: https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url#Connectingintegrated
2. Download the JDBC file and extract to your preferred location
3.open the auth folder matching your OS x64 or x86
4. copy sqljdbc_auth.dll file and paste in: C:\Program Files\Java\jdk_version\bin
restart either eclipse or netbeans

In a case when you do not have permission to copy the files to folders.
set thi as a VM argument
In eclipse

1) Create a folder 'sqlauth' in your C: drive, and copy the dll file sqljdbc_auth.dll to the folder
2) Go to Run> Run Configurations
3) Choose the 'Arguments' tab for your class
4) Add the below code in VM arguments:
         -Djava.library.path="C:\\sqlauth"
5) Hit 'Apply' and click 'Run'

https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url#Connectingintegrated
https://blogs.msdn.microsoft.com/jdbcteam/2017/03/31/jdbc-download-center-pages-and-repackaging/



Tuesday, January 23, 2018

Clean Boot

Issue     : the data collector set or one of t its dependencies is already in use
Solution :

Clean boot

Let’s disable all startup items and third party services when booting. This method will help us determine if this issue is caused by a loading program or service. Please perform the following steps:

1. Click the Start Button type "msconfig" (without quotation marks) in the Start Search box, and then press Enter.

Note: If prompted, please click Continue on the User Account Control (UAC) window.

2. Click the "Services" tab, check the "Hide All Microsoft Services" box and click "Disable All" (if it is not gray).

3. Click the "Startup" tab, click "Disable All" and click "OK".

Then, restart the computer. When the "System Configuration Utility" window appears, please check the "Don't show this message or launch the System Configuration Utility when Windows starts" box and click OK.

https://social.technet.microsoft.com/Forums/office/en-US/6c95b8cc-d7f5-46ed-8858-06e4f16204d3/start-and-stop-error-for-performance-counter-in-perfmon-of-windows-server-2008?forum=winserverManagement

Get the queries run by a users

USE master
go
SELECT sdest.DatabaseName
    ,sdes.session_id
    ,sdes.[host_name]
    ,sdes.[program_name]
    ,sdes.client_interface_name
    ,sdes.login_name
    ,sdes.login_time
    ,sdes.nt_domain
    ,sdes.nt_user_name
    ,sdec.client_net_address
    ,sdec.local_net_address
    ,sdest.ObjName
    ,sdest.Query
FROM sys.dm_exec_sessions AS sdes
INNER JOIN sys.dm_exec_connections AS sdec ON sdec.session_id = sdes.session_id
CROSS APPLY (
    SELECT db_name(dbid) AS DatabaseName
        ,object_id(objectid) AS ObjName
        ,ISNULL((
                SELECT TEXT AS [processing-instruction(definition)]
                FROM sys.dm_exec_sql_text(sdec.most_recent_sql_handle)
                FOR XML PATH('')
                    ,TYPE
                ), '') AS Query

    FROM sys.dm_exec_sql_text(sdec.most_recent_sql_handle)
    ) sdest
where sdes.session_id <> @@SPID
--and sdes.nt_user_name = '' -- Put the username here !
--ANd login_name ='user'
ORDER BY sdec.session_id

Thursday, January 11, 2018

Always on group database fails. May be not accessible or recovery mode. This may due to some incident happened in the database server.

1.       Always on group database fails. May be not accessible or recovery mode. This may due to some incident happened in the database server.

Soution: set online database from primary database. Eg: let’s say you have two servers and each server has two availability groups. Server1 has availGroup1 as primary and server2 has availGroup2 as primary. The database ‘myDB’ has failed and it’s a member of availGroup2. AvailGroup2 resides in server2 and try to bring the ‘myDB’ online in server2.

ALTER DATABASE MyDB SET ONLINE

If you execute this in other server, you might get the error as

-----------------------------------------------------
Msg 5052, Level 16, State 1, Line 2
ALTER DATABASE is not permitted while a database is in the Restoring state.
Msg 5069, Level 16, State 1, Line 2

ALTER DATABASE statement failed.
---------------------------------------------------------

Give little time. Server2, MyDb will come online.
After MyDB comes online add database to the AvailGroup2 from the server2 and connect with the MyDb in the server1.




Monday, January 8, 2018

Fix for Certificate Error in Chrome - NET::ERR_CERT_COMMON_NAME_INVALID

this error comes in chrome due to upgration done in the TLS process.
Below URL has described this clearly.

http://www.expta.com/2017/06/fix-for-certificate-error-in-chrome.html