Posts

Showing posts from 2017

How to change SQL Server Authentication Mode by using TSQL Query

SQL Server Authentication mode can be changed by using GUI. Simply click on Server -> Properties -> Security. There you can change the SQL Server Authentication mode to 1. Windows Authentication mode 2. SQL Server and Windows Authentication mode( Mixed Mode) You can also use below scripts to check and change the SQL Server Authentication mode: --Use this to Check the SQL Server Authentication Mode SELECT CASE SERVERPROPERTY('IsIntegratedSecurityOnly')  WHEN 1 THEN 'Windows Authentication'  WHEN 0 THEN 'Windows and SQL Server Authentication'  END as [SQLServerAuthenticationMode] ------------------------------------------------------------------------------ --To Change to Windows Authentication USE [master] GO EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 1 GO -----------------------------------------------------------------------------

How to pass data through variables and insert the values into database table using SqlCommand Statement with C#

Let's create our table first: CREATE TABLE [dbo] . [Member] (     [Id] [int] NULL,     [Name] [varchar] ( 60 ) NULL,     [Dob] [date] NULL,      [Email] [varchar] ( 80 ) NULL,      [Phone] [Nvarchar] ( 20 ) NULL ) The below C# script can be used to insert the variable values to “dbo.Member” table just created . using  System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; using System.IO; namespace DataWorldWithGbengaOridupa.com_CSharp_Tutorial {     class Program     {         static void Main( string [] args)         {             //The datetime and Log folder will be used for error log file in case of error. It is important.             string datetime = DateTime.Now.ToString( "yyyyMMddHHmmss" );             string LogFolder = @"C:\Log\";             try             {                 //Create C

Using Python GUID 'tkinter' for displaying Menu and Toolbar sample

from tkinter import * def Test(): print ( "Testing!" ) root = Tk() # create a menu menu = Menu(root) root.config( menu =menu) filemenu = Menu(menu) menu.add_cascade( label = "File" , menu =filemenu) filemenu.add_command( label = "New" , command =Test) filemenu.add_command( label = "Open..." , command =Test) filemenu.add_separator() filemenu.add_command( label = "Exit" , command =Test) helpmenu = Menu(menu) menu.add_cascade( label = "Help" , menu =helpmenu) helpmenu.add_command( label = "About..." , command =Test) # create a toolbar toolbar = Frame(root) b = Button(toolbar, text = "new" , width = 6 , command =Test) b.pack( side =LEFT, padx = 2 , pady = 2 ) b = Button(toolbar, text = "open" , width = 6 , command =Test) b.pack( side =LEFT, padx = 2 , pady = 2 ) mainloop() Here is a sample to play with.

How to backup multiple SQL Server Databases in SQL Server

Example: You need to take backup of multiple databases from SQL Server Instance and be created with date_time. Below is a script you can use(Cursor); USE MASTER GO DECLARE @BackupPath varchar(100) --Provide the backup path SET @BackupPath = 'C:\Backup\' DECLARE @DBName AS varchar(200) DECLARE Cur CURSOR FOR --Change the select query for the DBs you like to backup SELECT  name FROM    sys.databases WHERE   database_id >4  --(i.e excluding the following 'master, tempdb, model and msdb') OPEN Cur FETCH NEXT FROM Cur INTO @DBName WHILE @@FETCH_STATUS = 0 BEGIN   DECLARE @SQL varchar(max) = NULL   DECLARE @DBNamewithDateTime varchar(128) = NULL   SET @DBNamewithDateTime = @DBName + '_' + REPLACE(CAST(GETDATE()        AS date), '-', '') + '_' + REPLACE(CAST(CAST(GETDATE() AS time)        AS char(8)), ':', '')   SET @SQL = 'BACKUP DATABASE [' + @DBName + '] TO  DISK = N''' +

How to copy files from a folder to another folder and rename with datetime using C#

Intro : Below C# Script can be used to copy all the files from a folder to another folder and add date-time to destination copied file names. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace dataworldwithgbengaoridupa.com_CSharp_Tutorial {     class Program     {         static void Main(string[] args)         {             try             {                 //Provide your source folder path here                 string SourceFolder = @"C:\Source\";                 //Provide Destination Folder path                 string DestinationFolder = @"C:\Destination\";                 //datetime variable to use as part of file name                 string datetime = DateTime.Now.ToString("yyyyMMddHHmmss");                 var files = new DirectoryInfo(SourceFolder).GetFiles("*.*");                 //Loop through files and Copy to destin

IT - Service

Image
Best place for your IT solutions. Email : Gbenga. Unstoppable @gmail.com

How to get the last day of any month

Image
Example: You are on a project and you need to automate how you retrieve the last day of the month every time you pull data because you use it almost all the time. This is a quick solution, by using a Scalar-valued function. Run this: USE YourDBName GO Create Function [dbo].[FnGetLastDayOfMonth] -- Input parameters ( @Anydate datetime ) RETURNS datetime AS /******************************************************************** Returns the last day of the month (extracted from the date passed) *********************************************************************/ BEGIN -- add one month to the datepassed SET @Anydate = DATEADD(m,1,@Anydate) RETURN DATEADD(d,-datepart(d,@Anydate),@Anydate) END You can test this in a simple select statement;  SELECT [dbo].[fnGetLastDayOfMonth](GETDATE()) as  LastDayOfTheMonth Here is the result when i ran it;

How to Get Row Count Of All The Tables In SQL Server Database

Image
Example:   Need to do a quick  row count for all the tables in a database . This is a quick way to find the row count for all the tables in a database. The Cursor with Count(*) can be slow as it has to count rows for each of the table. USE YourDBName GO SELECT OBJECT_NAME ( id ) AS TableName ,        rowcnt           AS [RowCount] FROM   sysindexes s        INNER JOIN sys.tables t                ON s.id = t. OBJECT_ID WHERE   s.indid IN ( 0 , 1 , 255 )        AND is_ms_shipped = 0 I ran above query on Test DB and got below information: Fig 1: Get Row Count for all the Tables in SQL Server Database                                                     

What's New in SQL Server 2016

  Check this out. Below is the summary of SQL Server 2016 new features.  1          Query Store a)      It contains query work load history . b)      It can enforce polices to direct SQL Server Query processor to execute in a specific     manner c)         Captures queries, query plans, runtime statistics, etc. d)        New system views are added to support Query store e)         Helps system-wide or database level performance analysis and troubleshooting 2        Column Store a)         Column store index on your in-memory table for higher throughput b)       Columnstore indexes achieve up to 10x greater data compression than row store indexes. This greatly reduces the IO required to execute analytics queries and therefore improves query performance 3         Live Query Statistics a)         Live Query plans with system resources consumption such as CPU and memory for all running queries in the plan b)         It helps you watch change of statistics d