<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/category/database/sql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 02 Jun 2021 15:23:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>SQL &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Foolproof Tips for Reading and Shrinking Transaction logs in SQL Server</title>
		<link>https://www.sibeeshpassion.com/transaction-log-in-sql-server/</link>
					<comments>https://www.sibeeshpassion.com/transaction-log-in-sql-server/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Andrew Jackson]]></dc:creator>
		<pubDate>Thu, 07 Jun 2018 13:35:37 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Transaction]]></category>
		<category><![CDATA[Transaction logs in SQL]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=12943</guid>

					<description><![CDATA[[toc] Query-1: SQL Server log file growing unexpectedly? “We are wondering why transaction logs keep on increasing?? It become so gigantic, the transaction log size get increase from 135GB to 350GB and that&#8217;s so annoying. My drive containing data store is losing space. I am using Full Recovery Model and the logs are backed up hourly. Please help me out why this is happening and what should be done to stop growing it too big?” SOLVED: SQL Server Log File Getting Too Big SQL Server Transaction logs records all activities of transaction logs. Each database in SQL Server instance consists [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Query-1: SQL Server log file growing unexpectedly?</h2>
<p><i>“We are wondering why transaction logs keep on increasing?? It become so gigantic, the transaction log size get increase from 135GB to 350GB and that&#8217;s so annoying. My drive containing data store is losing space. I am using Full Recovery Model and the logs are backed up hourly. Please help me out why this is happening and what should be done to stop growing it too big?”</i></p>
<h3>SOLVED: SQL Server Log File Getting Too Big</h3>
<p>SQL Server Transaction logs records all activities of transaction logs. Each database in SQL Server instance consists of logs that records all the modification done in the databases. It is crucial component of the databases. Any modification, deletion can be tracked down in transaction logs.</p>
<p>There are various reasons of transaction log file getting expanded. The possible reasons are listed below:</p>
<ul>
<li>Large transaction log file</li>
<li>Transaction taking too long to complete</li>
<li>Transaction operation fail &amp; may start to rollback</li>
<li>Issue in performance</li>
<li>Blocking issue</li>
<li>Database participating in AlwaysOn availability group</li>
</ul>
<h4>What to do for stopping growing log file too big</h4>
<ol>
<li>Change the type of Recovery Model to Simple Recovery Model only if you are fine with not able to restore logs hence, failed point in time recovery. It is because if you are truncating your logs, you are breaking Transaction log LSN &amp; if any disaster occur, you will not able to restore T-logs. Hence if you are fine with this situation, then change your Recovery model to Simple. This will not allow any extra growth of log file.</li>
<li>Take T-log backup every hour in Full recovery Model, your transaction log will keep on growing until you take backup and truncate of it. While taking hourly T-log backup, the logs will grow until one hour, but after this it would truncate all commited transaction.</li>
</ol>
<p>Sometimes it might happen that you are in Simple Recovery Model, but your logs are still growing!!! Reason being is long running transaction. If your transaction taking long time when deleting thousand records in one delete statement, then logs will not be able to truncate until delete operation is done.</p>
<p>You can save yourself by maintaining proper size of log file or monitoring the usage of transaction.</p>
<p>By doing this, you can cut down the size of Transaction log.</p>
<h2>Query-2 How To Shrink Transaction logs File in SQL Server?</h2>
<p><i>“My log file size is growing continuously. Why is this happening?? I am lacking my disk space. I want to shrink my Transaction log file. Can anyone tell me how to shrink transaction logs in SQL Server. What will be the after effects if I shrink the log file. </i></p>
<h3>SOLVED: Reduce SQL Server Database Transaction Log File</h3>
<p>Relax!! There are several reasons for transaction log file growth. Long Running transaction, lack of taking log backup are some of the reasons which result in transaction log growth. Databases running for business purposes or production requires appropriate recovery model to be chosen for log management.</p>
<p>Log truncation frees up the log file space so that logs can reuse it. Truncation occur automatically if the database is backed up in Simple Recovery Model or after log backup when database is in Full Recovery Model.</p>
<p>Here I will resolve your shrink issue by two methods: By using SQL Server Management Studio and by using T-SQL.</p>
<h4><strong>Shrink By SQL Server Management Studio:</strong></h4>
<ul>
<li>Right Click on your Database&#8211;&gt;Tasks&#8211;&gt;Shrink&#8212;&gt;Files.</li>
<li>You will get the <strong>Shrink File</strong> Window, Change the File Type to <strong>Log</strong>.</li>
<li>There are three different actions under Shrink Action option. Either release the unused space, or shrink file to reorganize pages before releasing unused space, or empty file by migrating the data to other files in the same filegroup. Choose it according to your need.</li>
</ul>
<h4><strong>Shrink By T-SQL:</strong></h4>
<p>You can simply shrink transaction log file by running DBCC SHRINKFILE after taking log back. If you are using Simple Recovery Model, run below code:</p>
<p><code> DBCC SHRINKFILE (TestDB_log, 1)</code></p>
<p>If your database is in Full Recovery Model, first of all, set it to Simple Recovery Model, Then run DBCC SHRINKFILE and then set it to full.</p>
<p><strong>Caution:</strong> Setting database again in Full Recovery Model leads to loss of data in the Log. So, if you dont care about losing your log data, then definitely go for it!</p>
<h4><strong>Tips when you plan to shrink database or file: </strong></h4>
<ul>
<li>Shrink operation found to be most effective after delete or drop table operation as it create lot of unused space.</li>
<li>If you are repeatedly shrinking your database and you notice that the size of database grows again. Alert!! Shrinking database is a wasted operation, as most database require free space for regular day-to-day operation. This indicates that the space that was shrunk was a part of regular operation.</li>
<li>You should not shrink your database or data file after rebuilding indexes. As shrinking increases fragmentation to extreme level.</li>
<li>Do not ON Auto_Shrink option. (Unless you have very urgent requirement)</li>
</ul>
<h4>Is Shrinking database Bad?</h4>
<p>Well, Yes.</p>
<p>After shrinking operation,you will definitely be able to reduce the size of the database. But Wait!! Check your Fragmentation level first. It is found to be way too much!!!</p>
<p>Shrink operation increases the value of the fragmentation way too much. And higher fragmentation costs you poor performance of the database.</p>
<p>While if you are thinking that you can reduce fragmentation by using rebuild index, let me alert you, this will definitely reduce your fragmentation level. But Let me check the size of the database The database size increases way higher than the original.</p>
<h2>Query-3 How to check Deleted Records in SQL Server?</h2>
<p><i>“I am working in an organization and my manager assigned me work to check deleted database records of my database. How can I check my deleted records in SQL Server? Please Help me out from this situation.”</i></p>
<h3>SOLVED: Ways to Check Deleted Records in SQL Server</h3>
<p>You can track down your deleted database records by reading Transaction logs. And you can read it by using <strong>fn_dblog</strong> function. You can track down any DML as well as DDL activity like insert, delete , update, create operation by checking your transaction logs.</p>
<p>Fn_dblog function enables users to read all the database activity happening in SQL database. The function require begin and end LSN number for a transaction. You can easily trackdown the information of a person who did changes to your database. As LSN number are not in human readable form, SQL Server provide fn_dblog function for easy reading of transaction logs.</p>
<p>You can simply check your database activity by implementing below code:</p>
<p><code>USE ReadingDBLog;<br />
GO<br />
select [Current LSN],<br />
[Operation],<br />
[Transaction Name],<br />
[Transaction ID],<br />
[Transaction SID],<br />
[SPID],<br />
[Begin Time]<br />
FROM   fn_dblog(null,null)</code></p>
<h4><strong>How to Read Transaction Log Quickly</strong></h4>
<p>One quick way to read SQL Server database activity is to use SysTools <a href="https://www.systoolsgroup.com/sql-log-analyzer.html"><strong>SQL Log Viewer</strong></a>. It read &amp; analyse operation like insert, update, delete. The software previews all .ldf activities like transaction name, table name, query etc. You have option to choose the database from different mode ie Online &amp; Offline mode. You will able to fetch it from live databases. If your database is in Simple Recovery Mode, the tool is capable to recover deleted database records. You will get three different option for exporting. You can export it as in SQL Server Database , as CSV or as Compatible Script.</p>
<h2>Conclusion</h2>
<p>The blog covers various users queries about transaction logs along with its possible solution. I have discussed why transaction logs keep on increasing, how to track down your transaction details of your database and how to shrink transaction logs. I have also discussed some quick tips when you shrink your database.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/transaction-log-in-sql-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Copy Table Schema and Data from One Database to another Database in SQL Server</title>
		<link>https://www.sibeeshpassion.com/copy-table-schema-and-data-from-one-to-another-database/</link>
					<comments>https://www.sibeeshpassion.com/copy-table-schema-and-data-from-one-to-another-database/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Andrew Jackson]]></dc:creator>
		<pubDate>Thu, 26 Apr 2018 12:41:04 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database to Database]]></category>
		<category><![CDATA[MSSQL]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=12814</guid>

					<description><![CDATA[[toc] Problem: A few days ago, while migrating data from one database to another, I encountered an interesting problem which user faced a lot. “I have two databases, I have to copy tables data from one database to another. My query is how can I copy table schema from one database to another with its schema and data” In this blog, we will learn the easiest solution on how you can solve that query. Solution There are plenty of methods on how you can copy table schema and data from one database to another like Generate script wizard, Import/Export Wizard [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Problem:</h2>
<p>A few days ago, while migrating data from one database to another, I encountered an interesting problem which user faced a lot.</p>
<p><em>“I have two databases, I have to copy tables data from one database to another. My query is how can I copy table schema from one database to another with its schema and data”</em></p>
<p>In this blog, we will learn the easiest solution on how you can solve that query.</p>
<h2>Solution</h2>
<p>There are plenty of methods on how you can copy table schema and data from one database to another like Generate script wizard, Import/Export Wizard etc. But these methods are quite lengthy and requires users time.</p>
<p>The easiest solution to copy schema’s table from one database to another is to use SysTools SQL Server Database Migration Tool. You will able to migrate your tables schema by performing few steps.</p>
<h3>How to Copy Table Schema and Data from One Database to Another?</h3>
<ul>
<li>Launch <strong><a href="https://www.systoolsgroup.com/sql-server/migration/">SysTools SQL Server Database Migration Tool</a></strong>.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/1.png"><img fetchpriority="high" decoding="async" class="size-medium wp-image-12815" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/1-300x185.png" alt="Launch SysTools SQL Server Database Migration Tool" width="300" height="185" srcset="/wp-content/uploads/2018/04/1-300x185.png 300w, /wp-content/uploads/2018/04/1-768x473.png 768w, /wp-content/uploads/2018/04/1-400x247.png 400w, /wp-content/uploads/2018/04/1-973x600.png 973w, /wp-content/uploads/2018/04/1.png 579w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Click <strong>Open</strong> and load your database MDF file.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/3.png"><img decoding="async" class="size-medium wp-image-12816" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/3-300x185.png" alt="open MDF File" width="300" height="185" srcset="/wp-content/uploads/2018/04/3-300x185.png 300w, /wp-content/uploads/2018/04/3-768x474.png 768w, /wp-content/uploads/2018/04/3-1024x631.png 1024w, /wp-content/uploads/2018/04/3-400x247.png 400w, /wp-content/uploads/2018/04/3-973x600.png 973w, /wp-content/uploads/2018/04/3.png 1025w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Choose the <strong>Scan Modes</strong> accordingly and select the SQL Server version of your .mdf file.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/4.png"><img decoding="async" class="size-medium wp-image-12817" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/4-300x185.png" alt="select version" width="300" height="185" srcset="/wp-content/uploads/2018/04/4-300x185.png 300w, /wp-content/uploads/2018/04/4-768x474.png 768w, /wp-content/uploads/2018/04/4-400x247.png 400w, /wp-content/uploads/2018/04/4-973x600.png 973w, /wp-content/uploads/2018/04/4.png 579w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Select the database table from the left side, which you want to migrate to another database.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/5.png"><img decoding="async" class="size-medium wp-image-12818" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/5-300x185.png" alt="Select the database name" width="300" height="185" srcset="/wp-content/uploads/2018/04/5-300x185.png 300w, /wp-content/uploads/2018/04/5-768x473.png 768w, /wp-content/uploads/2018/04/5-400x247.png 400w, /wp-content/uploads/2018/04/5-973x600.png 973w, /wp-content/uploads/2018/04/5.png 1022w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Click on <strong>Export</strong> for migration process.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/6.png"><img decoding="async" class="size-medium wp-image-12819" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/6-300x185.png" alt="Click export to migrate the data" width="300" height="185" srcset="/wp-content/uploads/2018/04/6-300x185.png 300w, /wp-content/uploads/2018/04/6-768x473.png 768w, /wp-content/uploads/2018/04/6-400x246.png 400w, /wp-content/uploads/2018/04/6-974x600.png 974w, /wp-content/uploads/2018/04/6.png 1023w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>You will get two options for exporting. One is SQL Server Database and other is SQL Server Compatible Script. Choose it according to your need.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/7.png"><img decoding="async" class="size-medium wp-image-12820" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/7-300x247.png" alt="Two option for exporting" width="300" height="247" srcset="/wp-content/uploads/2018/04/7-300x247.png 300w, /wp-content/uploads/2018/04/7-400x329.png 400w, /wp-content/uploads/2018/04/7.png 624w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>After filling the Server credentials, Select the destination database as ‘<strong>Export to Existing database</strong>’</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/8.png"><img decoding="async" class="size-medium wp-image-12821" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/8-300x247.png" alt="Choose your desired destination location" width="300" height="247" srcset="/wp-content/uploads/2018/04/8-300x247.png 300w, /wp-content/uploads/2018/04/8-400x329.png 400w, /wp-content/uploads/2018/04/8.png 624w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>Software will fetch the databases and let you select the database on which you want to move the selected table.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/9.png"><img decoding="async" class="size-medium wp-image-12822" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/9-300x247.png" alt="fetch details od database" width="300" height="247" srcset="/wp-content/uploads/2018/04/9-300x247.png 300w, /wp-content/uploads/2018/04/9-400x329.png 400w, /wp-content/uploads/2018/04/9.png 623w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>You will get two options to export. Select ‘<strong>With Schema &amp; Data</strong>’. This option will copy schema &amp; data of your selected table from one database and export it to another and click <strong>Export</strong>.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/11.png"><img decoding="async" class="size-medium wp-image-12823" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/11-300x246.png" alt="Select Schema &amp; Data option" width="300" height="246" srcset="/wp-content/uploads/2018/04/11-300x246.png 300w, /wp-content/uploads/2018/04/11-400x328.png 400w, /wp-content/uploads/2018/04/11.png 625w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<li>You will get popup of Export complete.</li>
<p><a href="https://sibeeshpassion.com/wp-content/uploads/2018/04/12.png"><img decoding="async" class="size-medium wp-image-12824" src="https://sibeeshpassion.com/wp-content/uploads/2018/04/12-300x186.png" alt="Export complete" width="300" height="186" srcset="/wp-content/uploads/2018/04/12-300x186.png 300w, /wp-content/uploads/2018/04/12-768x476.png 768w, /wp-content/uploads/2018/04/12-400x248.png 400w, /wp-content/uploads/2018/04/12-969x600.png 969w, /wp-content/uploads/2018/04/12.png 577w" sizes="(max-width: 300px) 100vw, 300px" /></a>
</ul>
<h2>Conclusion</h2>
<p>The blog covers the easiest workaround of mostly faced users query on how to copy schema &amp; data from one database to another. You can also use Import/Export Wizard, Generate script wizard etc for object migration using SQL Server. But these methods has some limitations. In Import/Export wizard, the indexes and the key will not get transferred, you need to generate scripts for that. The export wizard fails if foreign keys connecting the tables together is not in a correct order. ‘Generate script’ method is used to generate a single script for tables schema, data, indexes and keys. But again, the limitation is this method doesn’t generate tables creation script in correct order.</p>
<p>So one can opt for SysTools SQL Database Migration Tool for fast migration of tables schema from one database to another.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/copy-table-schema-and-data-from-one-to-another-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Log File Corruption and Possible Recovery Methods</title>
		<link>https://www.sibeeshpassion.com/sql-log-file-corruption-and-possible-recovery-methods/</link>
					<comments>https://www.sibeeshpassion.com/sql-log-file-corruption-and-possible-recovery-methods/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Andrew Jackson]]></dc:creator>
		<pubDate>Mon, 12 Feb 2018 06:05:23 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[sql log file corruption]]></category>
		<category><![CDATA[sql server 2016]]></category>
		<category><![CDATA[sql transaction log]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=12618</guid>

					<description><![CDATA[[toc] Introduction Structured Query Language (commonly known as SQL) is a programming language used for managing data held in relational database management system (RDMS) consisting of data definition language, data manipulation language and a data control language. The SQL database comprises of following three files: Primary Database Files: Primary database file is the main database file (MDF) which points to another file in database and hence every database has one primary data file. The file is in the extension of .mdf Secondary Database Files: When the data of a database exceeds than a secondary database file is created which stores [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>Structured Query Language (commonly known as SQL) is a programming language used for managing data held in relational database management system (RDMS) consisting of data definition language, data manipulation language and a data control language. The SQL database comprises of following three files:</p>
<ol>
<li><strong>Primary Database Files</strong>: Primary database file is the <a href="http://sibeeshpassion.com/understand-the-internal-structure-of-sql-database-file/" target="_blank">main database file</a> (MDF) which points to another file in database and hence every database has one primary data file. The file is in the extension of .mdf</li>
<li><strong>Secondary Database Files</strong>: When the data of a database exceeds than a secondary database file is created which stores the data that exceeds MDF limit. Hence, multiple secondary data files can be created for a single database. The file is in the extension of .ndf</li>
<li>Log Files: These files maintain a log of all the transactions done in SQL Server Database so that that information can be later used to recover the database. There must exist one log file for each database and it is possible that more than one log file can be created for a single database. The file is in .ldf file extension.</li>
</ol>
<p>Log files (also known as transaction log) consist of actions executed on the database for database management to guarantee ACID properties over crashes or hardware failure. It is a file listing changes to the database, stored in a stable storage format</p>
<h2>Problem</h2>
<p>The log files of the SQL Server gets corrupted i.e. while the time we are performing some action upon SQL database, there exist some errors in between the process and due to which there is an interrupt in process.</p>
<h2>Causes of Log File Corruption in SQL Server</h2>
<ul>
<li>Viruses or other Malicious Software- In computer system, many viruses can infect and damage the log files and makes them inaccessible.</li>
<li>Terminating System Abnormally- If system/application is quit abnormally, then files are prone to be corrupted or damaged.</li>
<li>Input Output Configuration- The I/O subsystem is a vital component of the database used to store system and user databases. Hence if the configuration is disturbed on enhanced that it may lead to corruption in log files.</li>
<li>Storage Size Issue- The biggest reason behind the corruption of log files is the storage size. In case the data exceeds the limit of LDF, corruption is likely to occur.</li>
</ul>
<h3>Errors which Occurs Due to Log File Corruption</h3>
<p><strong>Error Message 1</strong>: StartLogFiles: The error exists when the log files are unable to start because the system could not find the file specified. So try to diagnose and correct the operating system error, and retry the operation.</p>
<p><strong>Error Message 2</strong>: File activation failure. The error occurs due to error in file on location ‘<strong>C:\ProgramFiles\MSSQLServer\MSSQL10_50.SQLEXPRESS\MSSQL\Log\ERRORLOG</strong>’.</p>
<p><strong>Error Message 3</strong>: The error message displays that the transaction log has been deleted or lost due to a hardware failure of a system or any other reason. The log files cannot be redeveloped because users perform open transactions on file.</p>
<p><strong>Error Message 4</strong>: Corrupted server of SQL database leads to corruption in backup of log files.</p>
<p><strong>Error Message 5</strong>: When database log is corrupted and a user is attempting to attach the log file to the new server then an error message displays with a message that ‘Could not open new database (Name of Database). CREATE DATABASE is aborted.</p>
<p><strong>Error Message 6</strong>: When the log database is attempted to attach but it gives an error while performing the attachment. The error displays one of the two number i.e. 9004 or 9001 notifying that you have to create a backup or it is necessary to rebuild the log.</p>
<h3>How to Recover Corrupted Log File in SQL Server?</h3>
<p>In order to repair a corrupt LDF file, use the WITH TABLOCK option for DBCC CHECKDB. It will recover the data from a corrupted LDF file that has been corrupted or damaged due to some reason such as logical corruption.</p>
<div id="attachment_12624" style="width: 613px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2018/02/dbcc-checkdb.png"><img decoding="async" aria-describedby="caption-attachment-12624" src="http://sibeeshpassion.com/wp-content/uploads/2018/02/dbcc-checkdb.png" alt="dbcc-checkdb" width="603" height="210" class="size-full wp-image-12624" srcset="/wp-content/uploads/2018/02/dbcc-checkdb.png 603w, /wp-content/uploads/2018/02/dbcc-checkdb-300x104.png 300w, /wp-content/uploads/2018/02/dbcc-checkdb-600x210.png 600w, /wp-content/uploads/2018/02/dbcc-checkdb-400x139.png 400w" sizes="(max-width: 603px) 100vw, 603px" /></a><p id="caption-attachment-12624" class="wp-caption-text">dbcc-checkdb</p></div>
<h2>Conclusion</h2>
<p>Through the above solution, we can recover SQL log file but not sure that the above procedure will recover complete log file data. However, there exists <a href="http://www.sqlserverlogexplorer.com/restore/" target="_blank">SQL Server transaction log recovery tool</a> through which you can restore database transaction log.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/sql-log-file-corruption-and-possible-recovery-methods/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Learn to Repair Corrupt MDF File with Perfection</title>
		<link>https://www.sibeeshpassion.com/learn-to-repair-corrupt-mdf-file-with-perfection/</link>
					<comments>https://www.sibeeshpassion.com/learn-to-repair-corrupt-mdf-file-with-perfection/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Andrew Jackson]]></dc:creator>
		<pubDate>Fri, 22 Sep 2017 17:07:34 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[repair corrupt mdf file]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12494</guid>

					<description><![CDATA[[toc] To get a damaged MDF file is not rare. However, the main cause behind it is that the file is prone to corruption. When this occurs, all data saved in the server database becomes inaccessible and therefore, it leads to data loss. In such circumstances, it is important to repair corrupt MDF file of server database storage. This segment will discuss how to execute the repair process. In addition, it will also give you in-depth information about MDF file, reasons, and way to repair damaged MDF file to store it in healthy form. Read further to know more. Quick [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<p>To get a damaged MDF file is not rare. However, the main cause behind it is that the file is prone to corruption. When this occurs, all data saved in the server database becomes inaccessible and therefore, it leads to data loss. In such circumstances, it is important to repair corrupt MDF file of server database storage.</p>
<p>This segment will discuss how to execute the repair process. In addition, it will also give you in-depth information about MDF file, reasons, and way to repair damaged MDF file to store it in healthy form. Read further to know more.</p>
<h2>Quick Glance on MDF File</h2>
<p>SQL Server MDF file is a relational management system of the database. Moreover, it is a primary data file of the database, which saves all the server data. Thus, you can even state it as the master database file of MS SQL Server. Every database of SQL Server would enclose at least one .mdf file.</p>
<p>It saves components like XML Indexes, Views, Indexes, Stored Procedures, Tables, Triggers, Rules, Keys, User Defined Functions, sparse columns, data types, file stream, the column set property data types. The .mdf file can be said as a primary element for managing SQL Server database.</p>
<h2>Reasons of MDF File Corruption</h2>
<p>There are various causes, which are answerable for damaging the primary file type of server.</p>
<ul>
<li>Unexpected power failure.</li>
<li>Various bugs in server.</li>
<li>Defective Operating System.</li>
<li>Sudden shutdown of the machine.</li>
<li>Issues with hard drive</li>
<li>Virus outbreaks.</li>
</ul>
<p>Thus, issues for your .mdf file revolving corrupt can be everything from malfunctioning of hardware to software and so it is necessary to fix corrupted MDF file.</p>
<h3>Technique to Repair Corrupt MDF File</h3>
<p><strong>Method 1: Inbuilt Tool</strong></p>
<p>There are some tools that make easy for users to fix corrupted MDF file of the server. Thus, make the saved data available. In fact, all these tools are series of commands in T-SQL programming language, which is called DBCC (Database Console Commands). The purpose of these statements in DBCC is to test physical and logical uniformity of MS SQL Server database files and fix troubling problems that continue.</p>
<p>DBCC CHECKDB is a command via which you can simply check the logical and physical integrity of all objects in precise MS SQL Server database. You can do it by implementing the mentioned operations successively:</p>
<ul>
<li>Run DBCC CHECKALLOC command in the database.</li>
<li>Run DBCC CHECKCATALOG command in the database.</li>
<li>Run DBCC CHECKTABLE on every view &amp; table in the database.</li>
<li>Verifying content of every indexed view present in the database.</li>
<li>Validating link-level constancy among table Metadata, file system directories files while saving varbinary (max) data utilizing FILESTREAM in the file system.</li>
<li>Confirming Service Broker data in database.</li>
<p>Once the above steps to repair damaged MDF file is completed then, if the application finds any issues of corruption or any errors, it recommends users have the usage of various recover options for fixing troublesome problems. The recover or repair options are:</p>
<li><strong>REPAIR_FAST</strong></li>
<p>It preserves syntax for compatibility of backward only; no repair actions are executed in definite. The syntax for this, Repair option is: DBCC CHECKDB (‘DB Name’, REPAIR_FAST).</p>
<li><strong>REPAIR_REBUILD</strong></li>
<p>This option of repair implements repair process, which scarcely has potentials of data loss. This can do quick repairs like repair of missing rows in non-clustered indexes, even time-consuming repairs like the rebuilding of indexes. The syntax is DBCC CHECKDB (‘DB Name’, REPAIR_REBUILD).</p>
<li><strong>REPAIR_ALLOW_DATA_LOSS</strong></li>
<p>This command creates an effort to fix all the issues, which are reported. However, it can root cause the loss of data as specified in repair command itself. The syntax is: DBCC CHECKDB (‘DB Name’, REPAIR_ALLOW_DATA_LOSS).</p>
</ul>
<h3>Limitations:</h3>
<ol>
<li>The specific database should be in single-user mode to be able to execute either of three commands of repair.</li>
<li>DBCC repair commands are not authenticated for memory-optimized tables.</li>
</ol>
<h3>Method 2: Trouble-Free Solution</h3>
<p>There can be a possibility that when your SQL Server database MDF file is corrupt and when you try to connect to SQL Server you will find that it is marked as SUSPECT. During such scenarios or the above discussed, you will not be able to connect to the database. To repair corrupt SQL Server MDF database file best option is to restore from a recent full database backup available.</p>
<p>If no recent backup available in such cases best possible approach is to repair corrupted MDF file of Microsoft SQL Server 2000, 2005, 2008, 2012 and 2016 with <strong><a href="https://www.systoolsgroup.com/sql-recovery.html" target="_blank">SQL Database Repair Tool</a></strong>. One of the most highly used and recommended software to repair corrupt SQL MDF file with the assurance of 99% guaranteed recovery.
</p>
<h3>Observational Verdict</h3>
<p>We have gone through the possible solution which you need to follow to recover a database in case MDF file get corrupted or database marked as SUSPECT. We serve you with the best of the best ways to repair corrupt MDF file. So, Hurry! What are you waiting for? You are raising the bar and we are taking it forward with the all in one and probably the best of solution repair damaged MDF database file.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/learn-to-repair-corrupt-mdf-file-with-perfection/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understand the Internal Structure of SQL Database File</title>
		<link>https://www.sibeeshpassion.com/understand-the-internal-structure-of-sql-database-file/</link>
					<comments>https://www.sibeeshpassion.com/understand-the-internal-structure-of-sql-database-file/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Andrew Jackson]]></dc:creator>
		<pubDate>Thu, 23 Mar 2017 15:55:59 +0000</pubDate>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Database File]]></category>
		<category><![CDATA[SQL Internal Structure]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12149</guid>

					<description><![CDATA[You must have thought how to store data in SQL Server? SQL Server is the platform, which provides a proper management of database. There is no doubt that it follows a strategy for the storage of all the files. All the users of SQL are aware with the fact that database objects are stored in MDF file. MDF files are responsible for the management of data in SQL Server. Therefore, in this article, we will learn the storage system of data in SQL Server data files. Database Files and its Storage Structure in SQL Server Database in SQL Server has [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>You must have thought how to store data in SQL Server? SQL Server is the platform, which provides a proper management of database. There is no doubt that it follows a strategy for the storage of all the files. All the users of SQL are aware with the fact that database objects are stored in MDF file. MDF files are responsible for the management of data in SQL Server. Therefore, in this article, we will learn the storage system of data in SQL Server data files.</p>
<h2>Database Files and its Storage Structure in SQL Server</h2>
<p>Database in SQL Server has two operating system files:</p>
<ul>
<li>Data Files</li>
<li>Log File</li>
</ul>
<p><strong>Data Files</strong></p>
<p>A data file consists of objects and data. Depending upon the needs, data files can be divided into two types: </p>
<p><strong>Primary Database File</strong></p>
<p>Each database has one primary data file. All the tables, database objects, indexes and views are stored in that file. The file extension of primary database file is .mdf. </p>
<p><strong>Secondary Database File</strong></p>
<p>This type is used at the time of exceeding the maximum allocated size for an individual file on Windows. It helps the database to increase in size. File extension for this file is .ndf.</p>
<p><strong>Log File</strong></p>
<p>Whenever users want to recover whole of the database in SQL Server, they require certain information, which are inside a log file. For one database there will be one log file and transactions of database are written on it even before to the data file. The file extension used by it is .ldf. LDF stands for Transactional Log file.</p>
<p><strong>Inner Structure of Data File</strong></p>
<p>Each database has its space to store the data, which is divided into different pages that are numbered from 0 to N. During the expansion of database files from its default size, those pages which are created newly are numbered from the last highest page number plus 1. In the similar way, at the time of shrinking of files it eliminates pages in decreasing order, which in the same manner starts from the highest page number. The basic unit of I/O for SQL Server operations is a page and each page is of 8 KB. A data file is a large array of pages. SQL Server stores different data with the help of multiple pages, Some of them are GAM, Index, IAM, Data, SGAM, and TextMix.</p>
<p><strong>Page Addressing:</strong></p>
<p>Now, if we analyze the pages addressing then we can see that every page in SQL Server is of equal size that is 8192 bytes. Each page has its own address, which is unique. It is a part of single database file. The ID of the file makes the first part of the unique address. Pages are numbered starting from 0. This is the mentioned format in which page address is written:</p>
<p> <strong>file number</strong>  :  <strong>page number</strong> </p>
<p>Data page is very essential among the page types. This is used for the storage of records to a database. </p>
<p>Structure of Data Page:</p>
<p>A data page contains three sections.</p>
<ul>
<li>Page Header</li>
<li>Page Body</li>
<li>Slot Array or Row offset</li>
</ul>
<p><strong>Page Header (0-95 bytes)</strong></p>
<p>The first 96 bytes of a particular page is known as page header, which consists of the information of the page.</p>
<p>That is, Page ID, No of records in that page and IDs of previous/next pages.</p>
<p><strong>Page Body</strong></p>
<p>It is that part where actual data is stored. It is followed by the free space and slot array. </p>
<p><strong>Slot Array</strong></p>
<p>Slot array, also known as off-set array, is an array of two-byte values, which is read by the SQL Server in reverse i.e. from the very end of the page. Slot array keep slot points to a byte in the page wherever a record begins. First slot of the record slot array is saved in the last two bytes of the page that points to the page of the first record saved at the page. </p>
<p><strong>Conclusion</strong></p>
<p>One of the essential things that should be kept in mind is that, In SQL Server, the database file (.mdf) store its data as per 8 kb pages and it is important for SQL Server to sustain the sequence of data pages as per their header information. In case of mismatching of information or the data is not stored in sequential order into data pages, there is possibility in the corruption of database or you may face <a href="http://www.sqlrecoverytool.com/fix-ms-sql-server-error-5172.html" target="_blank">SQL database error like 5172</a>, which is a header corruption error.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/understand-the-internal-structure-of-sql-database-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server CRUD Actions Using Node JS</title>
		<link>https://www.sibeeshpassion.com/sql-server-crud-actions-using-node-js/</link>
					<comments>https://www.sibeeshpassion.com/sql-server-crud-actions-using-node-js/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 27 Nov 2016 16:40:21 +0000</pubDate>
				<category><![CDATA[Node JS]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[CRUD in Node JS]]></category>
		<category><![CDATA[Database actions using Node JS]]></category>
		<category><![CDATA[Microsoft SQL Server client for Node JS]]></category>
		<category><![CDATA[MSSQL Node JS]]></category>
		<category><![CDATA[Node JS Application In Visual Studio]]></category>
		<category><![CDATA[SQL Server For Node JS]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11947</guid>

					<description><![CDATA[[toc] Introduction In this post we will see how we can perform CRUD application in our SQL database using Node JS. As you all know Node JS is a run time environment built on Chrome&#8217;s V8 JavaScript engine for server side and networking application. And it is an open source which supports cross platforms. Node JS applications are written in pure JavaScript. If you are new to Node JS, I strongly recommend you to read my previous post about Node JS here. Now let&#8217;s begin. Download source code SQL Server CRUD Actions Using Node JS Background There was a time [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>In this post we will see how we can perform CRUD application in our <a href="http://sibeeshpassion.com/category/SQL" target="_blank" rel="noopener">SQL </a> database using <a href="http://sibeeshpassion.com/category/Node-JS/" target="_blank" rel="noopener">Node JS</a>. As you all know Node JS is a run time environment built on Chrome&#8217;s V8 JavaScript engine for server side and networking application. And it is an open source which supports cross platforms. Node JS applications are written in pure <a href="http://sibeeshpassion.com/category/javascript/" target="_blank" rel="noopener">JavaScript</a>. If you are new to Node JS, I strongly recommend you to read my previous post about Node JS <a href="http://sibeeshpassion.com/introduction-to-node-js/" target="_blank" rel="noopener">here</a>. Now let&#8217;s begin.</p>
<h3><strong>Download source code</strong></h3>
<ul>
<li><a href="https://code.msdn.microsoft.com/SQL-Server-CRUD-Actions-6bc910fd" target="_blank" rel="noopener">SQL Server CRUD Actions Using Node JS </a></li>
</ul>
<h3><strong>Background</strong></h3>
<p>There was a time where we developers are depended on any server side languages to perform server side actions, few years back a company called Joyent, Inc brought us a solution for this. That is, we can do the server side actions if you know JavaScript. Because of the wonderful idea behind this, it became a great success. You can do server side actions without knowing a single code related to any server side languages like <a href="http://sibeeshpassion.com/category/csharp/" target="_blank" rel="noopener">C#</a> and <a href="http://sibeeshpassion.com/category/PHP/" target="_blank" rel="noopener">PHP</a>. Here we are going to see how you can do the database actions like Create, Read, Update, Delete using Node JS. I hope you will like this.</p>
<p>Before we start coding our Node JS application, we can set up Node JS tool available for <a href="http://sibeeshpassion.com/category/visual-studio/" target="_blank" rel="noopener">Visual Studio</a>.</p>
<h3><strong>Node JS tool for Visual Studio</strong></h3>
<blockquote><p>You can always run your Node JS code by using a command prompt, so setting up this tool is optional. If you install it, you can easily debug and develop Node JS. So I recommend you to install it.</p></blockquote>
<p>To download the tool, please click on this <a href="https://www.visualstudio.com/vs/node-js/" target="_blank" rel="noopener">link</a>. Once you have downloaded the set up file, you can start installing it.</p>
<div id="attachment_11948" style="width: 628px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_tool_for_Visual_Studio.png"><img decoding="async" aria-describedby="caption-attachment-11948" class="size-full wp-image-11948" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_tool_for_Visual_Studio.png" alt="node_js_tool_for_visual_studio" width="618" height="483" srcset="/wp-content/uploads/2016/11/Node_JS_tool_for_Visual_Studio.png 618w, /wp-content/uploads/2016/11/Node_JS_tool_for_Visual_Studio-300x234.png 300w, /wp-content/uploads/2016/11/Node_JS_tool_for_Visual_Studio-400x313.png 400w" sizes="(max-width: 618px) 100vw, 618px" /></a><p id="caption-attachment-11948" class="wp-caption-text">node_js_tool_for_visual_studio</p></div>
<p>So I hope you have installed the application, Now you can create a Node JS application in our Visual Studio.</p>
<h3><strong>Creating Node JS Application In Visual Studio</strong></h3>
<p>You can find an option as Node JS in your Add New Project window as follows. Please click on that and create a new project.</p>
<div id="attachment_11949" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/New_Node_JS_Project.png"><img decoding="async" aria-describedby="caption-attachment-11949" class="size-large wp-image-11949" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/New_Node_JS_Project-1024x709.png" alt="new_node_js_project" width="634" height="439" srcset="/wp-content/uploads/2016/11/New_Node_JS_Project-1024x709.png 1024w, /wp-content/uploads/2016/11/New_Node_JS_Project-300x208.png 300w, /wp-content/uploads/2016/11/New_Node_JS_Project-768x532.png 768w, /wp-content/uploads/2016/11/New_Node_JS_Project-160x110.png 160w, /wp-content/uploads/2016/11/New_Node_JS_Project-400x277.png 400w, /wp-content/uploads/2016/11/New_Node_JS_Project-866x600.png 866w, /wp-content/uploads/2016/11/New_Node_JS_Project.png 515w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11949" class="wp-caption-text">new_node_js_project</p></div>
<p>Now our Visual Studio is ready for coding, but as I mentioned earlier, we are going to use <a href="http://sibeeshpassion.com/category/sql-server/" target="_blank" rel="noopener">SQL Server</a> as our database. So we need to do some configuration related to that too. Let&#8217;s do it now.</p>
<h4><strong>Configure SQL Server For Node JS Development</strong></h4>
<p>You need to make sure that the following service are run.</p>
<ul>
<li>SQL Server</li>
<li>SQL Server Agent (Skip it if you are using SQLEXPRESS</li>
<li>SQL Server Browser</li>
</ul>
<p>To check the status of these service, you can always services by running <em>services.msc</em> in Run command window. Once you are done, you need to enables some protocols and assign a port to it. Now go to your SQL Server Configuration Manager. Most probably you can find the file in this <em>C:\Windows\SysWOW64</em> location, if you cant find it start window.</p>
<div id="attachment_11950" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/SQL_Server_Manager_Location-e1480260854402.png"><img decoding="async" aria-describedby="caption-attachment-11950" class="size-full wp-image-11950" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/SQL_Server_Manager_Location-e1480260854402.png" alt="sql_server_manager_location" width="634" height="206" srcset="/wp-content/uploads/2016/11/SQL_Server_Manager_Location-e1480260854402.png 634w, /wp-content/uploads/2016/11/SQL_Server_Manager_Location-e1480260854402-300x97.png 300w, /wp-content/uploads/2016/11/SQL_Server_Manager_Location-e1480260854402-400x130.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11950" class="wp-caption-text">sql_server_manager_location</p></div>
<p>Now go to SQL Server Network Configuration and click on Protocols for SQLEXPRESS(Your SQL Server) and Enable TCP/IP.</p>
<div id="attachment_11951" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Protocols_For_SQL_EXPRESS-e1480261046507.png"><img decoding="async" aria-describedby="caption-attachment-11951" class="size-full wp-image-11951" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Protocols_For_SQL_EXPRESS-e1480261046507.png" alt="protocols_for_sql_express" width="634" height="266" srcset="/wp-content/uploads/2016/11/Protocols_For_SQL_EXPRESS-e1480261046507.png 634w, /wp-content/uploads/2016/11/Protocols_For_SQL_EXPRESS-e1480261046507-300x126.png 300w, /wp-content/uploads/2016/11/Protocols_For_SQL_EXPRESS-e1480261046507-400x168.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11951" class="wp-caption-text">protocols_for_sql_express</p></div>
<p>Now right click and click on Properties on TCP/IP. Go to to IP Addresses and assign port for all the IP.</p>
<div id="attachment_11952" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server.png"><img decoding="async" aria-describedby="caption-attachment-11952" class="size-large wp-image-11952" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server-1024x707.png" alt="assigning_tcp_ip_port_in_sql_server" width="634" height="438" srcset="/wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server-1024x707.png 1024w, /wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server-300x207.png 300w, /wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server-768x530.png 768w, /wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server-160x110.png 160w, /wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server-400x276.png 400w, /wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server-869x600.png 869w, /wp-content/uploads/2016/11/Assigning_TCP_IP_Port_In_SQL_Server.png 517w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11952" class="wp-caption-text">assigning_tcp_ip_port_in_sql_server</p></div>
<p>If have done it, it is time to set up our database and insert some data. Please do not forget to restart your service, as it is mandatory to get updated the changes we have done in the configurations.</p>
<div id="attachment_11954" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Restart_SQL_EXPRESS.png"><img decoding="async" aria-describedby="caption-attachment-11954" class="size-large wp-image-11954" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Restart_SQL_EXPRESS-1024x595.png" alt="restart_sql_express" width="634" height="368" srcset="/wp-content/uploads/2016/11/Restart_SQL_EXPRESS-1024x595.png 1024w, /wp-content/uploads/2016/11/Restart_SQL_EXPRESS-300x174.png 300w, /wp-content/uploads/2016/11/Restart_SQL_EXPRESS-768x446.png 768w, /wp-content/uploads/2016/11/Restart_SQL_EXPRESS-400x233.png 400w, /wp-content/uploads/2016/11/Restart_SQL_EXPRESS-1032x600.png 1032w, /wp-content/uploads/2016/11/Restart_SQL_EXPRESS.png 614w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11954" class="wp-caption-text">restart_sql_express</p></div>
<h4><strong>Creating database</strong></h4>
<p>Here I am creating a database with name &#8220;TrialDB&#8221;, you can always create a DB by running the query given below.</p>
<p>[sql]<br />
USE [master]<br />
GO</p>
<p>/****** Object: Database [TrialDB] Script Date: 20-11-2016 03:54:53 PM ******/<br />
CREATE DATABASE [TrialDB]<br />
CONTAINMENT = NONE<br />
ON PRIMARY<br />
( NAME = N&#8217;TrialDB&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\TrialDB.mdf&#8217; , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )<br />
LOG ON<br />
( NAME = N&#8217;TrialDB_log&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\TrialDB_log.ldf&#8217; , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET COMPATIBILITY_LEVEL = 130<br />
GO</p>
<p>IF (1 = FULLTEXTSERVICEPROPERTY(&#8216;IsFullTextInstalled&#8217;))<br />
begin<br />
EXEC [TrialDB].[dbo].[sp_fulltext_database] @action = &#8216;enable&#8217;<br />
end<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET ANSI_NULL_DEFAULT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET ANSI_NULLS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET ANSI_PADDING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET ANSI_WARNINGS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET ARITHABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET AUTO_CLOSE OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET AUTO_SHRINK OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET AUTO_UPDATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET CURSOR_CLOSE_ON_COMMIT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET CURSOR_DEFAULT GLOBAL<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET CONCAT_NULL_YIELDS_NULL OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET NUMERIC_ROUNDABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET QUOTED_IDENTIFIER OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET RECURSIVE_TRIGGERS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET DISABLE_BROKER<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET DATE_CORRELATION_OPTIMIZATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET TRUSTWORTHY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET ALLOW_SNAPSHOT_ISOLATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET PARAMETERIZATION SIMPLE<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET READ_COMMITTED_SNAPSHOT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET HONOR_BROKER_PRIORITY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET RECOVERY SIMPLE<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET MULTI_USER<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET PAGE_VERIFY CHECKSUM<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET DB_CHAINING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET TARGET_RECOVERY_TIME = 60 SECONDS<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET DELAYED_DURABILITY = DISABLED<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET QUERY_STORE = OFF<br />
GO</p>
<p>USE [TrialDB]<br />
GO</p>
<p>ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 0;<br />
GO</p>
<p>ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET MAXDOP = PRIMARY;<br />
GO</p>
<p>ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = OFF;<br />
GO</p>
<p>ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET LEGACY_CARDINALITY_ESTIMATION = PRIMARY;<br />
GO</p>
<p>ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = ON;<br />
GO</p>
<p>ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET PARAMETER_SNIFFING = PRIMARY;<br />
GO</p>
<p>ALTER DATABASE SCOPED CONFIGURATION SET QUERY_OPTIMIZER_HOTFIXES = OFF;<br />
GO</p>
<p>ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET QUERY_OPTIMIZER_HOTFIXES = PRIMARY;<br />
GO</p>
<p>ALTER DATABASE [TrialDB] SET READ_WRITE<br />
GO<br />
[/sql]</p>
<p><strong>Create a table and insert data in database</strong></p>
<p>To create a table, you can run the query below.</p>
<p>[sql]<br />
USE [TrialDB]<br />
GO</p>
<p>/****** Object: Table [dbo].[Course] Script Date: 20-11-2016 03:57:30 PM ******/<br />
SET ANSI_NULLS ON<br />
GO</p>
<p>SET QUOTED_IDENTIFIER ON<br />
GO</p>
<p>CREATE TABLE [dbo].[Course](<br />
[CourseID] [int] NOT NULL,<br />
[CourseName] [nvarchar](50) NOT NULL,<br />
[CourseDescription] [nvarchar](100) NULL,<br />
CONSTRAINT [PK_Course] PRIMARY KEY CLUSTERED<br />
(<br />
[CourseID] ASC<br />
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]<br />
) ON [PRIMARY]</p>
<p>GO<br />
[/sql]</p>
<p>Now we can insert few data to our newly created table.</p>
<p>[sql]<br />
USE [TrialDB]<br />
GO</p>
<p>INSERT INTO [dbo].[Course]<br />
([CourseID]<br />
,[CourseName]<br />
,[CourseDescription])<br />
VALUES<br />
(1<br />
,&#8217;C#&#8217;<br />
,&#8217;Learn C# in 7 days&#8217;)<br />
INSERT INTO [dbo].[Course]<br />
([CourseID]<br />
,[CourseName]<br />
,[CourseDescription])<br />
VALUES<br />
(2<br />
,&#8217;Asp.Net&#8217;<br />
,&#8217;Learn Asp.Net in 7 days&#8217;)<br />
INSERT INTO [dbo].[Course]<br />
([CourseID]<br />
,[CourseName]<br />
,[CourseDescription])<br />
VALUES<br />
(3<br />
,&#8217;SQL&#8217;<br />
,&#8217;Learn SQL in 7 days&#8217;)<br />
INSERT INTO [dbo].[Course]<br />
([CourseID]<br />
,[CourseName]<br />
,[CourseDescription])<br />
VALUES<br />
(4<br />
,&#8217;JavaScript&#8217;<br />
,&#8217;Learn JavaScript in 7 days&#8217;)<br />
GO<br />
[/sql]</p>
<p>So our data is ready, that means we are all set to write our Node JS application. Go to the application we created and you can see a JS file there, normally named as <em>server.js</em>. Here I am going to change the name as <em>App.js</em>.</p>
<h4><strong>MSSQL &#8211; Microsoft SQL Server client for Node.js</strong></h4>
<p>You can find many packages for our day to day life in Node JS, what you need to do all is , just install that package and start using it. Here we are going to use a package called MSSQL.</p>
<p>Node-MSSQL</p>
<ul>
<li>Has unified interface for multiple TDS drivers.</li>
<li>Has built-in connection pooling.</li>
<li>Supports built-in JSON serialization introduced in SQL Server 2016.</li>
<li>Supports Stored Procedures, Transactions, Prepared Statements, Bulk Load and TVP.</li>
<li>Supports serialization of Geography and Geometry CLR types.</li>
<li>Has smart JS data type to SQL data type mapper.</li>
<li>Supports Promises, Streams and standard callbacks.</li>
<li>Supports ES6 tagged template literals.</li>
<li>Is stable and tested in production environment.</li>
<li>Is well documented.</li>
</ul>
<p>You can find more about the package <a href="https://www.npmjs.com/package/mssql" target="_blank" rel="noopener">here</a>. You can easily install this package by running the following command in your Nuget Package Manager Console.</p>
<p>[csharp]<br />
npm install mssql<br />
[/csharp]</p>
<div id="attachment_11953" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/MSSQL_Node_JS_Install.png"><img decoding="async" aria-describedby="caption-attachment-11953" class="size-large wp-image-11953" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/MSSQL_Node_JS_Install-1024x236.png" alt="mssql_node_js_install" width="634" height="146" srcset="/wp-content/uploads/2016/11/MSSQL_Node_JS_Install-1024x236.png 1024w, /wp-content/uploads/2016/11/MSSQL_Node_JS_Install-300x69.png 300w, /wp-content/uploads/2016/11/MSSQL_Node_JS_Install-768x177.png 768w, /wp-content/uploads/2016/11/MSSQL_Node_JS_Install-400x92.png 400w, /wp-content/uploads/2016/11/MSSQL_Node_JS_Install.png 1466w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11953" class="wp-caption-text">mssql_node_js_install</p></div>
<p>Now we can load this package by using a function called require.</p>
<p>[js]<br />
//MSSQL Instance Creation<br />
var sqlInstance = require(&#8220;mssql&#8221;);<br />
[/js]</p>
<p>Then, you can set the database configurations as preceding.</p>
<p>[js]<br />
/Database configuration<br />
var setUp = {<br />
server: &#8216;localhost&#8217;,<br />
database: &#8216;TrialDB&#8217;,<br />
user: &#8216;sa&#8217;,<br />
password: &#8216;sa&#8217;,<br />
port: 1433<br />
};<br />
[/js]</p>
<p>Once you have a configuration set up, you can connect your database by using connect() function.</p>
<p>[js]<br />
sqlInstance.connect(setUp)<br />
[/js]</p>
<p>Now we can perform the CRUD operations. Are you ready?</p>
<h4><strong>Select all the data from database using Node JS</strong></h4>
<p>[js]<br />
// To retrieve all the data &#8211; Start<br />
new sqlInstance.Request()<br />
.query(&#8220;select * from Course&#8221;)<br />
.then(function (dbData) {<br />
if (dbData == null || dbData.length === 0)<br />
return;<br />
console.dir(&#8216;All the courses&#8217;);<br />
console.dir(dbData);<br />
})<br />
.catch(function (error) {<br />
console.dir(error);<br />
});</p>
<p>// To retrieve all the data &#8211; End<br />
[/js]</p>
<p>Now run your application and see the output as preceding.</p>
<div id="attachment_11955" style="width: 593px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Select_All_Data_From_Database.png"><img decoding="async" aria-describedby="caption-attachment-11955" class="size-full wp-image-11955" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Select_All_Data_From_Database.png" alt="node_js_select_all_data_from_database" width="583" height="414" srcset="/wp-content/uploads/2016/11/Node_JS_Select_All_Data_From_Database.png 583w, /wp-content/uploads/2016/11/Node_JS_Select_All_Data_From_Database-300x213.png 300w, /wp-content/uploads/2016/11/Node_JS_Select_All_Data_From_Database-400x284.png 400w" sizes="(max-width: 583px) 100vw, 583px" /></a><p id="caption-attachment-11955" class="wp-caption-text">node_js_select_all_data_from_database</p></div>
<h4><strong>Select data with where condition from database using Node JS</strong></h4>
<p>You can always select a particular record by giving an appropriate select query as follows.</p>
<p>[js]<br />
// To retrieve specicfic data &#8211; Start<br />
var value = 2;<br />
new sqlInstance.Request()<br />
.input(&#8220;param&#8221;, sqlInstance.Int, value)<br />
.query(&#8220;select * from Course where CourseID = @param&#8221;)<br />
.then(function (dbData) {<br />
if (dbData == null || dbData.length === 0)<br />
return;<br />
console.dir(&#8216;Course with ID = 2&#8217;);<br />
console.dir(dbData);<br />
})<br />
.catch(function (error) {<br />
console.dir(error);<br />
});<br />
// To retrieve specicfic data &#8211; End<br />
[/js]</p>
<p>So what would be the output of the above code? Any idea?</p>
<div id="attachment_11956" style="width: 593px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Select_Particular_Data_From_Database.png"><img decoding="async" aria-describedby="caption-attachment-11956" class="size-full wp-image-11956" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Select_Particular_Data_From_Database.png" alt="node_js_select_particular_data_from_database" width="583" height="414" srcset="/wp-content/uploads/2016/11/Node_JS_Select_Particular_Data_From_Database.png 583w, /wp-content/uploads/2016/11/Node_JS_Select_Particular_Data_From_Database-300x213.png 300w, /wp-content/uploads/2016/11/Node_JS_Select_Particular_Data_From_Database-400x284.png 400w" sizes="(max-width: 583px) 100vw, 583px" /></a><p id="caption-attachment-11956" class="wp-caption-text">node_js_select_particular_data_from_database</p></div>
<h4><strong>Insert data to database using Node JS</strong></h4>
<p>We can always perform some insert query too using Node JS, the difference will be here is, as we have Transactions in SQL we will include that too here. Following code performs an insert operation.</p>
<p>[js]<br />
// Insert data &#8211; Start<br />
var dbConn = new sqlInstance.Connection(setUp,<br />
function (err) {<br />
var myTransaction = new sqlInstance.Transaction(dbConn);<br />
myTransaction.begin(function (error) {<br />
var rollBack = false;<br />
myTransaction.on(&#8216;rollback&#8217;,<br />
function (aborted) {<br />
rollBack = true;<br />
});<br />
new sqlInstance.Request(myTransaction)<br />
.query(&#8220;INSERT INTO [dbo].[Course] ([CourseName],[CourseDescription]) VALUES (&#8216;Node js&#8217;, &#8216;Learn Node JS in 7 days&#8217;)&#8221;,<br />
function (err, recordset) {<br />
if (err) {<br />
if (!rollBack) {<br />
myTransaction.rollback(function (err) {<br />
console.dir(err);<br />
});<br />
}<br />
} else {<br />
myTransaction.commit().then(function (recordset) {<br />
console.dir(&#8216;Data is inserted successfully!&#8217;);<br />
}).catch(function (err) {<br />
console.dir(&#8216;Error in transaction commit &#8216; + err);<br />
});<br />
}<br />
});<br />
});<br />
});<br />
// Insert data &#8211; End<br />
[/js]</p>
<p>So let&#8217;s run it and see the output.</p>
<div id="attachment_11957" style="width: 593px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Insert_Data_To_Database.png"><img decoding="async" aria-describedby="caption-attachment-11957" class="size-full wp-image-11957" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Insert_Data_To_Database.png" alt="node_js_insert_data_to_database" width="583" height="414" srcset="/wp-content/uploads/2016/11/Node_JS_Insert_Data_To_Database.png 583w, /wp-content/uploads/2016/11/Node_JS_Insert_Data_To_Database-300x213.png 300w, /wp-content/uploads/2016/11/Node_JS_Insert_Data_To_Database-400x284.png 400w" sizes="(max-width: 583px) 100vw, 583px" /></a><p id="caption-attachment-11957" class="wp-caption-text">node_js_insert_data_to_database</p></div>
<h4><strong>Delete data from database using Node JS</strong></h4>
<p>As we performed insert operation, we can do the same for delete operation as below.</p>
<p>[js]<br />
// Delete data &#8211; Start<br />
var delValue = 4;<br />
var dbConn = new sqlInstance.Connection(setUp,<br />
function (err) {<br />
var myTransaction = new sqlInstance.Transaction(dbConn);<br />
myTransaction.begin(function (error) {<br />
var rollBack = false;<br />
myTransaction.on(&#8216;rollback&#8217;,<br />
function (aborted) {<br />
rollBack = true;<br />
});<br />
new sqlInstance.Request(myTransaction)<br />
.query(&#8220;DELETE FROM [dbo].[Course] WHERE CourseID=&#8221; + delValue,<br />
function (err, recordset) {<br />
if (err) {<br />
if (!rollBack) {<br />
myTransaction.rollback(function (err) {<br />
console.dir(err);<br />
});<br />
}<br />
} else {<br />
myTransaction.commit().then(function (recordset) {<br />
console.dir(&#8216;Data is deleted successfully!&#8217;);<br />
}).catch(function (err) {<br />
console.dir(&#8216;Error in transaction commit &#8216; + err);<br />
});<br />
}<br />
});<br />
});<br />
});<br />
// Delete data &#8211; End<br />
[/js]</p>
<p>Now run your application and see whether the data is deleted.</p>
<div id="attachment_11958" style="width: 593px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Delete_Data_From_Database.png"><img decoding="async" aria-describedby="caption-attachment-11958" class="size-full wp-image-11958" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Delete_Data_From_Database.png" alt="node_js_delete_data_from_database" width="583" height="414" srcset="/wp-content/uploads/2016/11/Node_JS_Delete_Data_From_Database.png 583w, /wp-content/uploads/2016/11/Node_JS_Delete_Data_From_Database-300x213.png 300w, /wp-content/uploads/2016/11/Node_JS_Delete_Data_From_Database-400x284.png 400w" sizes="(max-width: 583px) 100vw, 583px" /></a><p id="caption-attachment-11958" class="wp-caption-text">node_js_delete_data_from_database</p></div>
<h4><strong>Update data from database using Node JS</strong></h4>
<p>The only action pending here to perform is UPDATE. Am I right? Let&#8217;s do that too.</p>
<p>[js]<br />
// Update data &#8211; Start<br />
var updValue = 3;<br />
var dbConn = new sqlInstance.Connection(setUp,<br />
function (err) {<br />
var myTransaction = new sqlInstance.Transaction(dbConn);<br />
myTransaction.begin(function (error) {<br />
var rollBack = false;<br />
myTransaction.on(&#8216;rollback&#8217;,<br />
function (aborted) {<br />
rollBack = true;<br />
});<br />
new sqlInstance.Request(myTransaction)<br />
.query(&#8220;UPDATE [dbo].[Course] SET [CourseName] = &#8216;Test&#8217; WHERE CourseID=&#8221; + updValue,<br />
function (err, recordset) {<br />
if (err) {<br />
if (!rollBack) {<br />
myTransaction.rollback(function (err) {<br />
console.dir(err);<br />
});<br />
}<br />
} else {<br />
myTransaction.commit().then(function (recordset) {<br />
console.dir(&#8216;Data is updated successfully!&#8217;);<br />
}).catch(function (err) {<br />
console.dir(&#8216;Error in transaction commit &#8216; + err);<br />
});<br />
}<br />
});<br />
});<br />
});<br />
// Update data &#8211; End<br />
[/js]</p>
<p>Here goes the output.</p>
<div id="attachment_11959" style="width: 593px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Update_Data_From_Database.png"><img decoding="async" aria-describedby="caption-attachment-11959" class="size-full wp-image-11959" src="http://sibeeshpassion.com/wp-content/uploads/2016/11/Node_JS_Update_Data_From_Database.png" alt="node_js_update_data_from_database" width="583" height="414" srcset="/wp-content/uploads/2016/11/Node_JS_Update_Data_From_Database.png 583w, /wp-content/uploads/2016/11/Node_JS_Update_Data_From_Database-300x213.png 300w, /wp-content/uploads/2016/11/Node_JS_Update_Data_From_Database-400x284.png 400w" sizes="(max-width: 583px) 100vw, 583px" /></a><p id="caption-attachment-11959" class="wp-caption-text">node_js_update_data_from_database</p></div>
<p>You can always download the source code attached to see the complete code and application. Happy coding!.</p>
<h3><strong>See also</strong></h3>
<ul>
<li><a href="https://www.npmjs.com/package/mssql" target="_blank" rel="noopener">MSSQL Package for Node JS</a></li>
<li><a href="https://nodejs.org/en/" target="_blank" rel="noopener">Node js</a></li>
</ul>
<h3><strong>Conclusion</strong></h3>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h3><strong>Your turn. What do you think?</strong></h3>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/sql-server-crud-actions-using-node-js/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
		<item>
		<title>Working With Test Client In Asp Net Web API Help Page</title>
		<link>https://www.sibeeshpassion.com/working-with-test-client-in-asp-net-web-api-help-page/</link>
					<comments>https://www.sibeeshpassion.com/working-with-test-client-in-asp-net-web-api-help-page/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 31 May 2016 00:00:33 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Web API]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[How to test Web API]]></category>
		<category><![CDATA[Test Web API]]></category>
		<category><![CDATA[Web API Tester]]></category>
		<category><![CDATA[WebApiTestClient]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11654</guid>

					<description><![CDATA[[toc] Introduction In this article we are going to see how we test our API with the help of a package called WebApiTestClient. As you all know, if you create a sample API project you will get a folder HelpPage in Areas. This is for adding the XML description to each controller and actions we use in our API. If you document it well, any one can understand your API, so that you don&#8217;t need to explain what your API will do and what would be the output. If you are new to HelpPage implementation in API, please see here: [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>In this article we are going to see how we test our API with the help of a package called <em>WebApiTestClient</em>. As you all know, if you create a sample API project you will get a folder HelpPage in Areas. This is for adding the XML description to each controller and actions we use in our API. If you document it well, any one can understand your API, so that you don&#8217;t need to explain what your API will do and what would be the output. If you are new to HelpPage implementation in API, please see here: <a href="http://sibeeshpassion.com/working-with-api-help-page-controller-action-description-in-web-api/" target="_blank" rel="noopener">API help page controller action description in Web API</a>. Here I am going to create a <a href="http://sibeeshpassion.com/category/web-api" target="_blank" rel="noopener">Web API</a> with the help page descriptions in <a href="http://sibeeshpassion.com/category/tools/visual-studio/" target="_blank" rel="noopener">Visual Studio</a> 2015. And once after the project is ready I will install the <em>WebApiTestClient </em> package to my solution. I hope you will like this.</p>
<blockquote><p>Please be noted that this package is not officially released by Microsoft. This is a prototype created by <a href="https://social.msdn.microsoft.com/profile/Yao+-+MSFT" target="_blank" rel="noopener">Yao &#8211; MSFT</a></p></blockquote>
<h2><strong>Download the source code</strong></h2>
<p>You can always download the source code here: <a href="https://code.msdn.microsoft.com/Working-With-Test-Client-9fb65ba9" target="_blank" rel="noopener">API Test Client</a></p>
<h2><strong>Background</strong></h2>
<p>For the past few months, I had been working with API projects. Recently I was asked to create an application to test the API I created so that the testing team can test the API easily. Yes I agree that we have tools like Fiddler and Post Man for the same. Still we thought to create our own. As I started my development, I came to know about the package <em>WebApiTestClient</em> which does what we wanted. Finally we decided to stop developing the application and used this wonderful package. Here I am going to show you how can we use this.</p>
<h2><strong>Prerequisites</strong></h2>
<ul>
<li>Visual Studio With Web API Installed</li>
</ul>
<h2><strong>Things we are going to do</strong></h2>
<p>The following are the tasks we are going to do.</p>
<ul>
<li>Setting up database</li>
<li>Creating an Entity Framework</li>
<li>Creating API controller with the Model Created</li>
<li>Installing <em>WebApiTestClient</em></li>
<li>Configuring <em>WebApiTestClient</em></li>
<li>Testing <em>WebApiTestClient</em></li>
</ul>
<h2><strong>Setting up database</strong></h2>
<p>Here I am going to create a database which I created for my demo purposes, you can always create this database by running the queries mentioned here.</p>
<h3><strong>Create database</strong></h3>
<p>[sql]<br />
USE [master]<br />
GO</p>
<p>/****** Object: Database [TrialsDB] Script Date: 5/12/2016 10:56:41 AM ******/<br />
CREATE DATABASE [TrialsDB]<br />
CONTAINMENT = NONE<br />
ON PRIMARY<br />
( NAME = N&#8217;TrialsDB&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB.mdf&#8217; , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )<br />
LOG ON<br />
( NAME = N&#8217;TrialsDB_log&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB_log.ldf&#8217; , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET COMPATIBILITY_LEVEL = 110<br />
GO</p>
<p>IF (1 = FULLTEXTSERVICEPROPERTY(&#8216;IsFullTextInstalled&#8217;))<br />
begin<br />
EXEC [TrialsDB].[dbo].[sp_fulltext_database] @action = &#8216;enable&#8217;<br />
end<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_NULL_DEFAULT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_NULLS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_PADDING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_WARNINGS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ARITHABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_CLOSE OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_CREATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_SHRINK OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_UPDATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CURSOR_CLOSE_ON_COMMIT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CURSOR_DEFAULT GLOBAL<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CONCAT_NULL_YIELDS_NULL OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET NUMERIC_ROUNDABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET QUOTED_IDENTIFIER OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET RECURSIVE_TRIGGERS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DISABLE_BROKER<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DATE_CORRELATION_OPTIMIZATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET TRUSTWORTHY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ALLOW_SNAPSHOT_ISOLATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET PARAMETERIZATION SIMPLE<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET READ_COMMITTED_SNAPSHOT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET HONOR_BROKER_PRIORITY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET RECOVERY FULL<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET MULTI_USER<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET PAGE_VERIFY CHECKSUM<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DB_CHAINING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET TARGET_RECOVERY_TIME = 0 SECONDS<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET READ_WRITE<br />
GO<br />
[/sql]</p>
<h3><strong>Create table with data</strong></h3>
<p>[sql]<br />
USE [TrialsDB]<br />
GO<br />
/****** Object: Table [dbo].[Product] Script Date: 5/12/2016 10:54:48 AM ******/<br />
SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
CREATE TABLE [dbo].[Product](<br />
[ProductID] [int] NOT NULL,<br />
[Name] [nvarchar](max) NOT NULL,<br />
[ProductNumber] [nvarchar](25) NOT NULL,<br />
[MakeFlag] [bit] NOT NULL,<br />
[FinishedGoodsFlag] [bit] NOT NULL,<br />
[Color] [nvarchar](15) NULL,<br />
[SafetyStockLevel] [smallint] NOT NULL,<br />
[ReorderPoint] [smallint] NOT NULL,<br />
[StandardCost] [money] NOT NULL,<br />
[ListPrice] [money] NOT NULL,<br />
[Size] [nvarchar](5) NULL,<br />
[SizeUnitMeasureCode] [nchar](3) NULL,<br />
[WeightUnitMeasureCode] [nchar](3) NULL,<br />
[Weight] [decimal](8, 2) NULL,<br />
[DaysToManufacture] [int] NOT NULL,<br />
[ProductLine] [nchar](2) NULL,<br />
[Class] [nchar](2) NULL,<br />
[Style] [nchar](2) NULL,<br />
[ProductSubcategoryID] [int] NULL,<br />
[ProductModelID] [int] NULL,<br />
[SellStartDate] [datetime] NOT NULL,<br />
[SellEndDate] [datetime] NULL,<br />
[DiscontinuedDate] [datetime] NULL,<br />
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,<br />
[ModifiedDate] [datetime] NOT NULL<br />
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]<br />
GO<br />
INSERT [dbo].[Product] ([ProductID], [Name], [ProductNumber], [MakeFlag], [FinishedGoodsFlag], [Color], [SafetyStockLevel], [ReorderPoint], [StandardCost], [ListPrice], [Size], [SizeUnitMeasureCode], [WeightUnitMeasureCode], [Weight], [DaysToManufacture], [ProductLine], [Class], [Style], [ProductSubcategoryID], [ProductModelID], [SellStartDate], [SellEndDate], [DiscontinuedDate], [rowguid], [ModifiedDate]) VALUES (1, N&#8217;Adjustable Race&#8217;, N&#8217;AR-5381&#8242;, 0, 0, NULL, 1000, 750, 0.0000, 0.0000, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, CAST(0x0000921E00000000 AS DateTime), NULL, NULL, N&#8217;694215b7-08f7-4c0d-acb1-d734ba44c0c8&#8242;, CAST(0x00009A5C00A53CF8 AS DateTime))<br />
INSERT [dbo].[Product] ([ProductID], [Name], [ProductNumber], [MakeFlag], [FinishedGoodsFlag], [Color], [SafetyStockLevel], [ReorderPoint], [StandardCost], [ListPrice], [Size], [SizeUnitMeasureCode], [WeightUnitMeasureCode], [Weight], [DaysToManufacture], [ProductLine], [Class], [Style], [ProductSubcategoryID], [ProductModelID], [SellStartDate], [SellEndDate], [DiscontinuedDate], [rowguid], [ModifiedDate]) VALUES (2, N&#8217;Bearing Ball&#8217;, N&#8217;BA-8327&#8242;, 0, 0, NULL, 1000, 750, 0.0000, 0.0000, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, CAST(0x0000921E00000000 AS DateTime), NULL, NULL, N&#8217;58ae3c20-4f3a-4749-a7d4-d568806cc537&#8242;, CAST(0x00009A5C00A53CF8 AS DateTime))<br />
INSERT [dbo].[Product] ([ProductID], [Name], [ProductNumber], [MakeFlag], [FinishedGoodsFlag], [Color], [SafetyStockLevel], [ReorderPoint], [StandardCost], [ListPrice], [Size], [SizeUnitMeasureCode], [WeightUnitMeasureCode], [Weight], [DaysToManufacture], [ProductLine], [Class], [Style], [ProductSubcategoryID], [ProductModelID], [SellStartDate], [SellEndDate], [DiscontinuedDate], [rowguid], [ModifiedDate]) VALUES (3, N&#8217;BB Ball Bearing&#8217;, N&#8217;BE-2349&#8242;, 1, 0, NULL, 800, 600, 0.0000, 0.0000, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, CAST(0x0000921E00000000 AS DateTime), NULL, NULL, N&#8217;9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e&#8217;, CAST(0x00009A5C00A53CF8 AS DateTime))<br />
INSERT [dbo].[Product] ([ProductID], [Name], [ProductNumber], [MakeFlag], [FinishedGoodsFlag], [Color], [SafetyStockLevel], [ReorderPoint], [StandardCost], [ListPrice], [Size], [SizeUnitMeasureCode], [WeightUnitMeasureCode], [Weight], [DaysToManufacture], [ProductLine], [Class], [Style], [ProductSubcategoryID], [ProductModelID], [SellStartDate], [SellEndDate], [DiscontinuedDate], [rowguid], [ModifiedDate]) VALUES (4, N&#8217;Headset Ball Bearings&#8217;, N&#8217;BE-2908&#8242;, 0, 0, NULL, 800, 600, 0.0000, 0.0000, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, CAST(0x0000921E00000000 AS DateTime), NULL, NULL, N&#8217;ecfed6cb-51ff-49b5-b06c-7d8ac834db8b&#8217;, CAST(0x00009A5C00A53CF8 AS DateTime))<br />
INSERT [dbo].[Product] ([ProductID], [Name], [ProductNumber], [MakeFlag], [FinishedGoodsFlag], [Color], [SafetyStockLevel], [ReorderPoint], [StandardCost], [ListPrice], [Size], [SizeUnitMeasureCode], [WeightUnitMeasureCode], [Weight], [DaysToManufacture], [ProductLine], [Class], [Style], [ProductSubcategoryID], [ProductModelID], [SellStartDate], [SellEndDate], [DiscontinuedDate], [rowguid], [ModifiedDate]) VALUES (316, N&#8217;Blade&#8217;, N&#8217;BL-2036&#8242;, 1, 0, NULL, 800, 600, 0.0000, 0.0000, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, CAST(0x0000921E00000000 AS DateTime), NULL, NULL, N&#8217;e73e9750-603b-4131-89f5-3dd15ed5ff80&#8242;, CAST(0x00009A5C00A53CF8 AS DateTime))<br />
INSERT [dbo].[Product] ([ProductID], [Name], [ProductNumber], [MakeFlag], [FinishedGoodsFlag], [Color], [SafetyStockLevel], [ReorderPoint], [StandardCost], [ListPrice], [Size], [SizeUnitMeasureCode], [WeightUnitMeasureCode], [Weight], [DaysToManufacture], [ProductLine], [Class], [Style], [ProductSubcategoryID], [ProductModelID], [SellStartDate], [SellEndDate], [DiscontinuedDate], [rowguid], [ModifiedDate]) VALUES (317, N&#8217;LL Crankarm&#8217;, N&#8217;CA-5965&#8242;, 0, 0, N&#8217;Black&#8217;, 500, 375, 0.0000, 0.0000, NULL, NULL, NULL, NULL, 0, NULL, N&#8217;L &#8216;, NULL, NULL, NULL, CAST(0x0000921E00000000 AS DateTime), NULL, NULL, N&#8217;3c9d10b7-a6b2-4774-9963-c19dcee72fea&#8217;, CAST(0x00009A5C00A53CF8 AS DateTime))<br />
INSERT [dbo].[Product] ([ProductID], [Name], [ProductNumber], [MakeFlag], [FinishedGoodsFlag], [Color], [SafetyStockLevel], [ReorderPoint], [StandardCost], [ListPrice], [Size], [SizeUnitMeasureCode], [WeightUnitMeasureCode], [Weight], [DaysToManufacture], [ProductLine], [Class], [Style], [ProductSubcategoryID], [ProductModelID], [SellStartDate], [SellEndDate], [DiscontinuedDate], [rowguid], [ModifiedDate]) VALUES (318, N&#8217;ML Crankarm&#8217;, N&#8217;CA-6738&#8242;, 0, 0, N&#8217;Black&#8217;, 500, 375, 0.0000, 0.0000, NULL, NULL, NULL, NULL, 0, NULL, N&#8217;M &#8216;, NULL, NULL, NULL, CAST(0x0000921E00000000 AS DateTime), NULL, NULL, N&#8217;eabb9a92-fa07-4eab-8955-f0517b4a4ca7&#8217;, CAST(0x00009A5C00A53CF8 AS DateTime))<br />
[/sql]</p>
<h3>Create application</h3>
<p>Our database is ready, now create a Web API application in visual studio and then entity with the above mentioned database.</p>
<div id="attachment_11556" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Creating-Entity-e1463031313825.png"><img decoding="async" aria-describedby="caption-attachment-11556" class="size-large wp-image-11556" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Creating-Entity-1024x542.png" alt="Creating Entity" width="634" height="336" /></a><p id="caption-attachment-11556" class="wp-caption-text">Creating Entity</p></div>
<p>If you don&#8217;t know how to create an entity in your solution, please read that <a href="http://sibeeshpassion.com/web-api-with-angular-js/" target="_blank" rel="noopener">here</a>. I have mentioned the steps to be followed in that article. Once you have created the entity, you are good to go and create a API controller with the entity created. If you do so, The CRUD actions will be created automatically for you. You may need to edit those actions according to your needs.</p>
<div id="attachment_11557" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Web-API-2-Controller-with-actions-using-Entity-Framework-e1463031653319.png"><img decoding="async" aria-describedby="caption-attachment-11557" class="size-full wp-image-11557" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Web-API-2-Controller-with-actions-using-Entity-Framework-e1463031653319.png" alt="Web API 2 Controller with actions, using Entity Framework" width="650" height="457" srcset="/wp-content/uploads/2016/05/Web-API-2-Controller-with-actions-using-Entity-Framework-e1463031653319.png 650w, /wp-content/uploads/2016/05/Web-API-2-Controller-with-actions-using-Entity-Framework-e1463031653319-300x211.png 300w, /wp-content/uploads/2016/05/Web-API-2-Controller-with-actions-using-Entity-Framework-e1463031653319-400x281.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11557" class="wp-caption-text">Web API 2 Controller with actions, using Entity Framework</p></div>
<p>Select the Model Class, DBContext then name your controller and click OK. I hope a controller with the CRUD actions. Now we can modify that as follows.</p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Data;<br />
using System.Data.Entity;<br />
using System.Data.Entity.Infrastructure;<br />
using System.Linq;<br />
using System.Net;<br />
using System.Net.Http;<br />
using System.Web.Http;<br />
using System.Web.Http.Description;<br />
using ControllerActionDescriptions.Models;</p>
<p>namespace ControllerActionDescriptions.Controllers<br />
{<br />
public class ProductsController : ApiController<br />
{<br />
private TrialsDBEntities db = new TrialsDBEntities();<br />
#region GetProducts<br />
/// &lt;summary&gt;<br />
/// Get all the products available<br />
/// GET: api/Products<br />
/// &lt;/summary&gt;<br />
public IQueryable&lt;Product&gt; GetProducts()<br />
{<br />
return db.Products;<br />
}<br />
#endregion</p>
<p>#region GetProductWithParameter<br />
/// &lt;summary&gt;<br />
/// Get a single product by id<br />
/// GET: api/Products/5<br />
/// &lt;param name=&#8221;id&#8221;&gt;&lt;/param&gt;<br />
/// &lt;/summary&gt;<br />
[ResponseType(typeof(Product))]<br />
public IHttpActionResult GetProduct(int id)<br />
{<br />
Product product = db.Products.Find(id);<br />
if (product == null)<br />
{<br />
return NotFound();<br />
}</p>
<p>return Ok(product);<br />
}<br />
#endregion<br />
// PUT: api/Products/5<br />
[ResponseType(typeof(void))]<br />
public IHttpActionResult PutProduct(int id, Product product)<br />
{<br />
if (!ModelState.IsValid)<br />
{<br />
return BadRequest(ModelState);<br />
}</p>
<p>if (id != product.ProductID)<br />
{<br />
return BadRequest();<br />
}</p>
<p>db.Entry(product).State = EntityState.Modified;</p>
<p>try<br />
{<br />
db.SaveChanges();<br />
}<br />
catch (DbUpdateConcurrencyException)<br />
{<br />
if (!ProductExists(id))<br />
{<br />
return NotFound();<br />
}<br />
else<br />
{<br />
throw;<br />
}<br />
}</p>
<p>return StatusCode(HttpStatusCode.NoContent);<br />
}</p>
<p>// POST: api/Products<br />
[ResponseType(typeof(Product))]<br />
public IHttpActionResult PostProduct(Product product)<br />
{<br />
if (!ModelState.IsValid)<br />
{<br />
return BadRequest(ModelState);<br />
}</p>
<p>db.Products.Add(product);</p>
<p>try<br />
{<br />
db.SaveChanges();<br />
}<br />
catch (DbUpdateException)<br />
{<br />
if (ProductExists(product.ProductID))<br />
{<br />
return Conflict();<br />
}<br />
else<br />
{<br />
throw;<br />
}<br />
}</p>
<p>return CreatedAtRoute(&#8220;DefaultApi&#8221;, new { id = product.ProductID }, product);<br />
}</p>
<p>// DELETE: api/Products/5<br />
[ResponseType(typeof(Product))]<br />
public IHttpActionResult DeleteProduct(int id)<br />
{<br />
Product product = db.Products.Find(id);<br />
if (product == null)<br />
{<br />
return NotFound();<br />
}</p>
<p>db.Products.Remove(product);<br />
db.SaveChanges();</p>
<p>return Ok(product);<br />
}</p>
<p>protected override void Dispose(bool disposing)<br />
{<br />
if (disposing)<br />
{<br />
db.Dispose();<br />
}<br />
base.Dispose(disposing);<br />
}</p>
<p>private bool ProductExists(int id)<br />
{<br />
return db.Products.Count(e =&gt; e.ProductID == id) &gt; 0;<br />
}<br />
}<br />
}<br />
[/csharp]</p>
<h2><strong>Installing WebApiTestClient</strong></h2>
<p>To install the package, please go to your Package Manage Console from NuGet Package Manager and run the following command.</p>
<p>[csharp]<br />
Install-Package WebApiTestClient<br />
[/csharp]</p>
<p>You can always get the details about the package <a href="https://www.nuget.org/packages/WebApiTestClient" target="_blank" rel="noopener">here</a>.</p>
<p>Once you install the package, you can see some files are added to your Script and Area folder as preceding.</p>
<div id="attachment_11655" style="width: 291px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Script-and-Area-Folder.png"><img decoding="async" aria-describedby="caption-attachment-11655" class="size-full wp-image-11655" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Script-and-Area-Folder.png" alt="Script and Area Folder" width="281" height="780" srcset="/wp-content/uploads/2016/05/Script-and-Area-Folder.png 281w, /wp-content/uploads/2016/05/Script-and-Area-Folder-108x300.png 108w, /wp-content/uploads/2016/05/Script-and-Area-Folder-216x600.png 216w" sizes="(max-width: 281px) 100vw, 281px" /></a><p id="caption-attachment-11655" class="wp-caption-text">Script and Area Folder</p></div>
<h2><strong>Configuring WebApiTestClient</strong></h2>
<p>To configure the WebApiTestClient, please go to the folder Areas-&gt;Views-&gt;Help and then click on Api.cshtml</p>
<div id="attachment_11656" style="width: 272px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Api-Cshtml.png"><img decoding="async" aria-describedby="caption-attachment-11656" class="size-full wp-image-11656" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Api-Cshtml.png" alt="Api Cshtml" width="262" height="232" /></a><p id="caption-attachment-11656" class="wp-caption-text">Api Cshtml</p></div>
<p>This is the view shown when you click on each API in your help page. Now add the preceding code block to that view.</p>
<p>[html]<br />
@Html.DisplayForModel(&#8220;TestClientDialogs&#8221;)<br />
@section Scripts<br />
{<br />
&lt;link href=&#8221;~/Areas/HelpPage/HelpPage.css&#8221; rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; /&gt;<br />
@Html.DisplayForModel(&#8220;TestClientReferences&#8221;)<br />
}<br />
[/html]</p>
<div id="attachment_11657" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Code-Block-e1464327127249.png"><img decoding="async" aria-describedby="caption-attachment-11657" class="size-full wp-image-11657" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Code-Block-e1464327127249.png" alt="Code Block" width="650" height="503" srcset="/wp-content/uploads/2016/05/Code-Block-e1464327127249.png 461w, /wp-content/uploads/2016/05/Code-Block-e1464327127249-300x232.png 300w, /wp-content/uploads/2016/05/Code-Block-e1464327127249-400x310.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11657" class="wp-caption-text">Code Block</p></div>
<h2><strong>Testing WebApiTestClient</strong></h2>
<p>Now run your API application and go to the help page for any controller action, you can see a button called Test API on the bottom. If you click on that you will get a pop where you can test your API action.</p>
<div id="attachment_11658" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-API-Client-Output-e1464327451839.png"><img decoding="async" aria-describedby="caption-attachment-11658" class="size-large wp-image-11658" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-API-Client-Output-1024x451.png" alt="Test API Client Output" width="634" height="279" /></a><p id="caption-attachment-11658" class="wp-caption-text">Test API Client Output</p></div>
<p>Now if you send your request by clicking the send button, you will get an output as follows.</p>
<div id="attachment_11659" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-API-Client-Output-With-Response-e1464327640682.png"><img decoding="async" aria-describedby="caption-attachment-11659" class="size-full wp-image-11659" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-API-Client-Output-With-Response-e1464327640682.png" alt="Test API Client Output With Response" width="650" height="484" srcset="/wp-content/uploads/2016/05/Test-API-Client-Output-With-Response-e1464327640682.png 479w, /wp-content/uploads/2016/05/Test-API-Client-Output-With-Response-e1464327640682-300x223.png 300w, /wp-content/uploads/2016/05/Test-API-Client-Output-With-Response-e1464327640682-400x298.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11659" class="wp-caption-text">Test API Client Output With Response</p></div>
<p>You can always give id parameter as follows.</p>
<div id="attachment_11660" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-Client-With-Parameters-e1464327873548.png"><img decoding="async" aria-describedby="caption-attachment-11660" class="size-full wp-image-11660" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-Client-With-Parameters-e1464327873548.png" alt="Test Client With Parameters" width="650" height="302" srcset="/wp-content/uploads/2016/05/Test-Client-With-Parameters-e1464327873548.png 650w, /wp-content/uploads/2016/05/Test-Client-With-Parameters-e1464327873548-300x139.png 300w, /wp-content/uploads/2016/05/Test-Client-With-Parameters-e1464327873548-400x186.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11660" class="wp-caption-text">Test Client With Parameters</p></div>
<p>You can also give content-length and content-type in your post request as follows.</p>
<div id="attachment_11661" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-Client-With-Post-e1464328070355.png"><img decoding="async" aria-describedby="caption-attachment-11661" class="size-full wp-image-11661" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-Client-With-Post-e1464328070355.png" alt="Test Client With Post" width="650" height="468" srcset="/wp-content/uploads/2016/05/Test-Client-With-Post-e1464328070355.png 496w, /wp-content/uploads/2016/05/Test-Client-With-Post-e1464328070355-300x216.png 300w, /wp-content/uploads/2016/05/Test-Client-With-Post-e1464328070355-400x288.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11661" class="wp-caption-text">Test Client With Post</p></div>
<div id="attachment_11662" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-Client-With-PUT-Request-e1464328191663.png"><img decoding="async" aria-describedby="caption-attachment-11662" class="size-full wp-image-11662" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Test-Client-With-PUT-Request-e1464328191663.png" alt="Test Client With PUT Request" width="650" height="542" srcset="/wp-content/uploads/2016/05/Test-Client-With-PUT-Request-e1464328191663.png 428w, /wp-content/uploads/2016/05/Test-Client-With-PUT-Request-e1464328191663-300x250.png 300w, /wp-content/uploads/2016/05/Test-Client-With-PUT-Request-e1464328191663-400x334.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11662" class="wp-caption-text">Test Client With PUT Request</p></div>
<h2><strong>References</strong></h2>
<ul>
<li><a href="https://blogs.msdn.microsoft.com/yaohuang1/2012/12/02/adding-a-simple-test-client-to-asp-net-web-api-help-page/" target="_blank" rel="noopener">Sample Test Client</a></li>
<li><a href="https://www.nuget.org/packages/WebApiTestClient" target="_blank" rel="noopener">WebApiTestClient</a></li>
</ul>
<p>Author has already posted the source code in GitHub, please check <a href="https://github.com/yaohuang/WebApiTestClient" target="_blank" rel="noopener">here</a>.</p>
<p>Have a happy coding!.</p>
<h2><strong>Conclusion</strong></h2>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h2><strong>Your turn. What do you think?</strong></h2>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/working-with-test-client-in-asp-net-web-api-help-page/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Encrypt And Decrypt ConnectionString In Web.Config File</title>
		<link>https://www.sibeeshpassion.com/encrypt-and-decrypt-connectionstring-in-web-config-file/</link>
					<comments>https://www.sibeeshpassion.com/encrypt-and-decrypt-connectionstring-in-web-config-file/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 16 May 2016 10:33:46 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Command Prompt]]></category>
		<category><![CDATA[Decrypt ConnectionString]]></category>
		<category><![CDATA[Encrypt ConnectionString]]></category>
		<category><![CDATA[How To]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11565</guid>

					<description><![CDATA[In this article we are going to see how we can encrypt and secure our connection string in our web config file. As you all know the connection string is the pillar of our data. I mean, without a connection string you just can&#8217;t create an application which does some database actions like retrieving the data, creating the data. We all know that the connection string is placed in the file called web config, so others too. If anyone needs to get the database information of your application, the first place he/she may look at will be the web config [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we are going to see how we can encrypt and secure our connection string in our web config file. As you all know the connection string is the pillar of our data. I mean, without a connection string you just can&#8217;t create an application which does some database actions like retrieving the data, creating the data. We all know that the connection string is placed in the file called web config, so others too. If anyone needs to get the database information of your application, the first place he/she may look at will be the web config file. Am I right? It is always recommend to encrypt the connection string of your application because the data we have there is highly sensitive. It must be secured. Here I am going to show you a demo of how we can do that, You can do the same thing in your Web API project, MVC project, Asp.Net 5 project, or any kind of templates you works with. I hope you will like this.</p>
<p><strong>Background</strong></p>
<p>I used to secure my config file if I am the who starts the project. Here you will get to know how easy the procedure is to encrypt the connection string. There is only a few steps to be followed. I will explain those. </p>
<p><strong>Agenda</strong></p>
<p>The following is the agenda we are going to follow. </p>
<li>Create an empty project, it can be any template(Asp.Net 5, Web API, MVC&#8230;)</li>
<li>Add a connection string</li>
<li>Encrypt the connection string</li>
<li>Decrypt the connection string</li>
<p><strong>Perquisites </strong></p>
<li>Visual Studio</li>
<li>SQL Server</li>
<p><strong>Create an empty project</strong></p>
<p>To create an empty project, go to File->New->New Project->Name the project->Select Empty->Click OK. Hope you get a solution as follows.</p>
<div id="attachment_11566" style="width: 384px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Empty-Solution.png"><img decoding="async" aria-describedby="caption-attachment-11566" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Empty-Solution.png" alt="Empty Solution" width="374" height="285" class="size-full wp-image-11566" srcset="/wp-content/uploads/2016/05/Empty-Solution.png 374w, /wp-content/uploads/2016/05/Empty-Solution-300x229.png 300w" sizes="(max-width: 374px) 100vw, 374px" /></a><p id="caption-attachment-11566" class="wp-caption-text">Empty Solution</p></div>
<p>Now We will connect to a database. To connect, please click on the connect icon in your server explorer window and connect you Local/Server database.</p>
<div id="attachment_11567" style="width: 515px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Connect-to-Database.png"><img decoding="async" aria-describedby="caption-attachment-11567" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Connect-to-Database.png" alt="Connect to Database" width="505" height="873" class="size-full wp-image-11567" srcset="/wp-content/uploads/2016/05/Connect-to-Database.png 505w, /wp-content/uploads/2016/05/Connect-to-Database-174x300.png 174w, /wp-content/uploads/2016/05/Connect-to-Database-400x691.png 400w, /wp-content/uploads/2016/05/Connect-to-Database-347x600.png 347w" sizes="(max-width: 505px) 100vw, 505px" /></a><p id="caption-attachment-11567" class="wp-caption-text">Connect to Database</p></div>
<p><strong>Add a connection string</strong></p>
<p>Now it is time to add our connection string, hope you got your data source of the database we already connected. The connection string property must be placed under configuration tag in your web config file. Here is mine.</p>
<p>[xml]<br />
&lt;connectionStrings&gt;<br />
    &lt;add name=&quot;myConnection&quot; connectionString=&quot;Data Source=SIBEESHVENU\SQLEXPRESS;Initial Catalog=ReportServer$SQLEXPRESS;Integrated Security=True&quot; /&gt;<br />
  &lt;/connectionStrings&gt;<br />
[/xml]</p>
<p>Now we will create a web page and in the page load event we will fetch this connection string and write it as a response. </p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;</p>
<p>namespace EncryptConnectionString<br />
{<br />
    public partial class Default : System.Web.UI.Page<br />
    {<br />
        protected void Page_Load(object sender, EventArgs e)<br />
        {<br />
            if (!IsPostBack)<br />
            {<br />
                try<br />
                {<br />
                    string myCon = System.Configuration.ConfigurationManager.ConnectionStrings[&quot;myConnection&quot;].ConnectionString;<br />
                    if (myCon != null)<br />
                    {<br />
                        Response.Write(&quot;My connection string is :&quot; + myCon);<br />
                    }<br />
                }<br />
                catch (Exception)<br />
                {</p>
<p>                    throw;<br />
                }<br />
            }<br />
        }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Please run your page, you will see your connection string in your page.</p>
<div id="attachment_11568" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Connection-string-response-e1463302112567.png"><img decoding="async" aria-describedby="caption-attachment-11568" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Connection-string-response-1024x47.png" alt="Connection string response" width="634" height="29" class="size-large wp-image-11568" /></a><p id="caption-attachment-11568" class="wp-caption-text">Connection string response</p></div>
<p><strong>Encrypt connection string</strong></p>
<p>To start the process, you must open your command window with the admin privilege. Then type the following command.</p>
<p>[csharp]<br />
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319<br />
[/csharp]</p>
<p>This command will narrate you to the framework version folder given. Now right click on your project and click open folder in file explorer and then copy the location. For me it is <em>F:\Visual Studio\EncryptConnectionString\EncryptConnectionString</em>. Now please go back to your command prompt and type the command as follows.</p>
<p>[csharp]<br />
ASPNET_REGIIS -PEF &quot;connectionStrings&quot; &quot;F:\Visual Studio\EncryptConnectionString\EncryptConnectionString&quot;<br />
[/csharp]</p>
<p>Once you click the enter. You will get the output as follows.</p>
<div id="attachment_11569" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Encrypt-ConnectionString-Output-e1463303289891.png"><img decoding="async" aria-describedby="caption-attachment-11569" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Encrypt-ConnectionString-Output-e1463303289891.png" alt="Encrypt ConnectionString Output" width="650" height="422" class="size-full wp-image-11569" srcset="/wp-content/uploads/2016/05/Encrypt-ConnectionString-Output-e1463303289891.png 650w, /wp-content/uploads/2016/05/Encrypt-ConnectionString-Output-e1463303289891-300x195.png 300w, /wp-content/uploads/2016/05/Encrypt-ConnectionString-Output-e1463303289891-400x260.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11569" class="wp-caption-text">Encrypt ConnectionString Output</p></div>
<p>Please be noted that the text <em>connectionStrings</em> is case sensitive. If you don&#8217;t give it as it is, you will get an error as follows.</p>
<p>[csharp]<br />
C:\Windows\Microsoft.NET\Framework\v4.0.30319&gt;ASPNET_REGIIS -PEF &quot;connectionstrings&quot; &quot;F:\Visual Studio\EncryptConnectionString\EncryptConnectionString&quot;<br />
Microsoft (R) ASP.NET RegIIS version 4.0.30319.0<br />
Administration utility to install and uninstall ASP.NET on the local machine.<br />
Copyright (C) Microsoft Corporation.  All rights reserved.<br />
Encrypting configuration section&#8230;<br />
The configuration section &#8216;connectionstrings&#8217; was not found.<br />
Failed!<br />
[/csharp]</p>
<p>So please be careful while you type the commands. Now I am going back to our application and see the config file. Shall we? You can see the connection string is encrypted as follows.</p>
<p>[xml]<br />
&lt;connectionStrings configProtectionProvider=&quot;RsaProtectedConfigurationProvider&quot;&gt;<br />
    &lt;EncryptedData Type=&quot;http://www.w3.org/2001/04/xmlenc#Element&quot;<br />
      xmlns=&quot;http://www.w3.org/2001/04/xmlenc#&quot;&gt;<br />
      &lt;EncryptionMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#tripledes-cbc&quot; /&gt;<br />
      &lt;KeyInfo xmlns=&quot;http://www.w3.org/2000/09/xmldsig#&quot;&gt;<br />
        &lt;EncryptedKey xmlns=&quot;http://www.w3.org/2001/04/xmlenc#&quot;&gt;<br />
          &lt;EncryptionMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#rsa-1_5&quot; /&gt;<br />
          &lt;KeyInfo xmlns=&quot;http://www.w3.org/2000/09/xmldsig#&quot;&gt;<br />
            &lt;KeyName&gt;Rsa Key&lt;/KeyName&gt;<br />
          &lt;/KeyInfo&gt;<br />
          &lt;CipherData&gt;<br />
            &lt;CipherValue&gt;B4B3oZrbpQsYM7Eaq5smukqDj9XUYUCwygBYRG1iasN4ll5W4wAKVCIFCRfvOJGoIXzgqpyjAI30IKf5pnZ/xWqmo3p/wGfOKdMrzd041dt9llLGbxFpLJs0Nkm583PJ1FppXLAy7FOD0YoBVhG/PBtBgLjTQqcXRNbVcgufzuArlv/EH+7lzSNRclXSTMOPMtISF65hPI9ICj9qLx7RBGhVZ6uFZVFteyyuRd2i3D2r7wJfr6KflFkakdxp1OWE2JK4Ldb8kZSwAy3bNaI/qaV9EgIWt9wM6RZO/IrI3kI/bX8JuvirPw3j/+TLDB3MoIgKjSbLpR3GYTm9csPu8g==&lt;/CipherValue&gt;<br />
          &lt;/CipherData&gt;<br />
        &lt;/EncryptedKey&gt;<br />
      &lt;/KeyInfo&gt;<br />
      &lt;CipherData&gt;<br />
        &lt;CipherValue&gt;0n1Y6ScSNZDR4x1sXfK05w9h+pp2OrAEQFQsoAUP5Y/hPsfpJS/7jv21PbPlkYmdCzycM4PGGb0+fuffR3RuL1x0tn7rfyUdA9llTfkyRQKwS9xOmkMsVFXgQDr8P4aXGef1fZPE2gjhcjm/JQToLwsfQZK1gNr4d6cIPFNqKD6wt24F7fuySJPX3OgLb8wXfQMd7ij+JcZzNlnyNHbq/DIjxSpPOnMrC52t06Jj8F8+MsSud9GcijcFB2UhvLVXQwyZ51nEj6Tf36Zbca8bgw==&lt;/CipherValue&gt;<br />
      &lt;/CipherData&gt;<br />
    &lt;/EncryptedData&gt;<br />
  &lt;/connectionStrings&gt;<br />
[/xml]</p>
<p><strong>Decrypt connection string</strong></p>
<p>You can always decrypt the connection string if you want, to decrypt you just need follows the commands as follows in the command prompt.</p>
<p>[csharp]<br />
cd C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319<br />
[/csharp]</p>
<p>Once after you did you the above command you can execute the preceding one.</p>
<p>[csharp]<br />
ASPNET_REGIIS -PDF &quot;connectionStrings&quot; &quot;F:\Visual Studio\EncryptConnectionString\EncryptConnectionString&quot;<br />
[/csharp]</p>
<blockquote><p>The text &#8216;connectionString&#8217; is case sensitive as mentioned above</p></blockquote>
<p>If the command is correct, you can get an output as follows.</p>
<div id="attachment_11573" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/Decrypting-connectionString-e1463394161466.png"><img decoding="async" aria-describedby="caption-attachment-11573" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/Decrypting-connectionString-e1463394161466.png" alt="Decrypting connectionString" width="650" height="440" class="size-full wp-image-11573" srcset="/wp-content/uploads/2016/05/Decrypting-connectionString-e1463394161466.png 650w, /wp-content/uploads/2016/05/Decrypting-connectionString-e1463394161466-300x203.png 300w, /wp-content/uploads/2016/05/Decrypting-connectionString-e1463394161466-320x218.png 320w, /wp-content/uploads/2016/05/Decrypting-connectionString-e1463394161466-620x420.png 620w, /wp-content/uploads/2016/05/Decrypting-connectionString-e1463394161466-400x271.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11573" class="wp-caption-text">Decrypting connectionString</p></div>
<p>Now if you check your Web config again, you can see the connection string has got encrypted. Have a happy coding!.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/encrypt-and-decrypt-connectionstring-in-web-config-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Keyboard Query Shortcuts In SQL Server Management Studio</title>
		<link>https://www.sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/</link>
					<comments>https://www.sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 12 May 2016 00:00:53 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[Keyboard Shortcuts]]></category>
		<category><![CDATA[Query Shortcuts]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11543</guid>

					<description><![CDATA[In this article we are going to see some shortcuts that may be useful to you when you work with SQL Server Management Studio. You can always uses some custom queries too as query shortcuts in SSMS. Here I am going to show some most used the queries shortcuts. I hope you will like this. Background If you are a dot net developer or if you are working with any Microsoft technologies, you must have some experience in working with SQL and SQL Server Management Studio. But as a developer we always try to achieve the things in a simple [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we are going to see some shortcuts that may be useful to you when you work with SQL Server Management Studio. You can always uses some custom queries too as query shortcuts in SSMS. Here I am going to show some most used the queries shortcuts. I hope you will like this.</p>
<p><strong>Background</strong></p>
<p>If you are a dot net developer or if you are working with any Microsoft technologies, you must have some experience in working with SQL and SQL Server Management Studio. But as a developer we always try to achieve the things in a simple manner. Isn&#8217;t it? This is where we are going for keyboard shortcuts. We do have an option to set and use the keyboard shortcuts in SSMS too. I will explain those. </p>
<p><strong>Keyboard Query Shortcuts In SSMS</strong></p>
<p>First of all let me tell you an example of where we can use the keyboard shortcuts. We know how to create stored procedures right? There procedures are created in a folder called &#8216;Stored Procedures&#8217; under Programmability. Now let us assume that I have a stored procedure with name as <em>usp_Get_SalesOrderDetail</em>. Now if you need to see the queries we have written in that stored procedure, what will you do? You have two options,</p>
<li>Right click on the stored procedure and click on modify</li>
<li>Use the sp_helptext as <em>sp_helptext usp_Get_SalesOrderDetail</em></li>
<p>Now my question is, in this scenario, whenever you need to see the stored procedure you need to type sp_helptext right? How can we overcome this situation? Here we can set the keyboard shortcuts. </p>
<p><strong>Setting the keyboard shortcuts</strong></p>
<p>Go to Tools -> Options.</p>
<div id="attachment_11544" style="width: 359px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Tools_Options_.png"><img decoding="async" aria-describedby="caption-attachment-11544" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Tools_Options_.png" alt="Tools_Options" width="349" height="208" class="size-full wp-image-11544" srcset="/wp-content/uploads/2016/04/Tools_Options_.png 349w, /wp-content/uploads/2016/04/Tools_Options_-300x179.png 300w" sizes="(max-width: 349px) 100vw, 349px" /></a><p id="caption-attachment-11544" class="wp-caption-text">Tools_Options</p></div>
<p>Go to Environment -> Keyboard -> Query Shortcuts </p>
<div id="attachment_11545" style="width: 252px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png"><img decoding="async" aria-describedby="caption-attachment-11545" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png" alt="Environment_Keyboard_Query_Shortcuts_" width="242" height="341" class="size-full wp-image-11545" srcset="/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png 242w, /wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_-213x300.png 213w" sizes="(max-width: 242px) 100vw, 242px" /></a><p id="caption-attachment-11545" class="wp-caption-text">Environment_Keyboard_Query_Shortcuts_</p></div>
<p>On the right side you can see some shortcuts which are by default in SSMS. Now if you need to add a new one, just click on any column under Stored Procedure column.  </p>
<div id="attachment_11546" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png"><img decoding="async" aria-describedby="caption-attachment-11546" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png" alt="Adding_a_new_keyboard_shortcut" width="650" height="378" class="size-full wp-image-11546" srcset="/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png 650w, /wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975-300x174.png 300w, /wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975-400x233.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11546" class="wp-caption-text">Adding_a_new_keyboard_shortcut</p></div>
<p>Click OK. Now please go to a query window and select the stored procedure then press CTRL+3, it will show the stored procedure. </p>
<div id="attachment_11547" style="width: 352px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/sp_helptext_Results_.png"><img decoding="async" aria-describedby="caption-attachment-11547" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/sp_helptext_Results_.png" alt="sp_helptext_Results_" width="342" height="441" class="size-full wp-image-11547" srcset="/wp-content/uploads/2016/04/sp_helptext_Results_.png 342w, /wp-content/uploads/2016/04/sp_helptext_Results_-233x300.png 233w" sizes="(max-width: 342px) 100vw, 342px" /></a><p id="caption-attachment-11547" class="wp-caption-text">sp_helptext_Results_</p></div>
<p>No if you need to select all the records from a table when you select the table and press CTRL+5(You can select any key). You can make the shortcut as follows. </p>
<div id="attachment_11548" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Selct_Query_As_Keyboard_Shortcut-e1461589819987.png"><img decoding="async" aria-describedby="caption-attachment-11548" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Selct_Query_As_Keyboard_Shortcut-1024x438.png" alt="Selct_Query_As_Keyboard_Shortcut" width="634" height="271" class="size-large wp-image-11548" /></a><p id="caption-attachment-11548" class="wp-caption-text">Selct_Query_As_Keyboard_Shortcut</p></div>
<p>Now please go ahead and select the table name from the query window and press CTRL+4(The key we selected). I hope you got the result as expected. Have a happy coding!.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed</title>
		<link>https://www.sibeeshpassion.com/rule-oracle-jre-7-update-51-64-bit-or-higher-is-required-for-polybase-failed/</link>
					<comments>https://www.sibeeshpassion.com/rule-oracle-jre-7-update-51-64-bit-or-higher-is-required-for-polybase-failed/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 28 Mar 2016 00:00:29 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Rule Check Result]]></category>
		<category><![CDATA[SQL Errors]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server RC 1]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11435</guid>

					<description><![CDATA[In this article we will are going to see how we can fix the error Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed. You may get this error when you try to install SQL Server. I wast trying to install SQL Server 2016 Release Candidate 1, and I got this error while installation. The complete error is like this Rule Check Result, Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed. This computer does not have the Oracle Java SE Runtime Environment Version 7 Update 51 (64-bit) or higher [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we will are going to see how we can fix the error <em>Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed</em>. You may get this error when you try to install <a href="http://sibeeshpassion.com/category/sql/" target="_blank">SQL </a>Server. I wast trying to install SQL Server 2016 Release Candidate 1, and I got this error while installation. The complete error is like this <em>Rule Check Result, Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed. This computer does not have the Oracle Java SE Runtime Environment Version 7 Update 51 (64-bit) or higher installed. The Oracle Java SE Runtime Environment is software provided by a third party. Microsoft grants you no rights for such third-party software. You are responsible for and must separately locate, read and accept applicable third-party license terms.</em> I have fixed this issue, and here I am going to share you how you can also fix this error. I hope you will like this.</p>
<p><strong>Background</strong></p>
<p>As you all know, <a href="http://sibeeshpassion.com/category/Microsoft/" target="_blank">Microsoft </a> has already released SQL Server 2018 RC Version 1. So I wanted to give a try, and I decided to install the same. But at a stage in installation, I got an error which was not allowing me to continue further. I started to scratch my head. And finally I could find the solution. Here we will see that.</p>
<p><strong>Fix to Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed</strong></p>
<p>Once you have started the installation, you can see a window as follows. </p>
<div id="attachment_11436" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479.png"><img decoding="async" aria-describedby="caption-attachment-11436" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479.png" alt="Installation Center SQL Server Start" width="650" height="492" class="size-full wp-image-11436" srcset="/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479.png 650w, /wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479-300x227.png 300w, /wp-content/uploads/2016/03/Installation-Center-SQL-Server-Start-e1459093924479-400x303.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11436" class="wp-caption-text">Installation Center SQL Server Start</p></div>
<p>If you have not installed SQL Server yet, you must select &#8220;New SQL Server stand-alone installation&#8221;, or you can upgrade by selecting &#8220;Upgrade from a previous version&#8221;. So we have started installing the things. When you are step away to finish everything once you have selected the features to add. You will be getting the error as follows. </p>
<blockquote><p>
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Rule Check Result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Rule &#8220;Oracle JRE 7 Update 51 (64-bit) or higher is required for Polybase&#8221; failed.</p>
<p>This computer does not have the Oracle Java SE Runtime Environment Version 7 Update 51 (64-bit) or higher installed. The Oracle Java SE Runtime Environment is software provided by a third party. Microsoft grants you no rights for such third-party software. You are responsible for and must separately locate, read and accept applicable third-party license terms. To continue, download the Oracle SE Java Runtime Environment from http://go.microsoft.com/fwlink/?LinkId=526030.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
OK<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
</p></blockquote>
<p>As it is mentioned in the link provided in the link, you can always download and install the Java SE from that link. This link will be redirected to <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" target="_blank">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a>. </p>
<div id="attachment_11437" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Java-SE-e1459094342113.png"><img decoding="async" aria-describedby="caption-attachment-11437" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Java-SE-1024x562.png" alt="Java SE" width="634" height="348" class="size-large wp-image-11437" /></a><p id="caption-attachment-11437" class="wp-caption-text">Java SE</p></div>
<p>Now we have an another option that to disable the Java SE from the features selected. For that go back to the feature selection.</p>
<div id="attachment_11438" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609.png"><img decoding="async" aria-describedby="caption-attachment-11438" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609.png" alt="Feature Selection Installation Center SQL Server" width="650" height="495" class="size-full wp-image-11438" srcset="/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609.png 650w, /wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609-300x228.png 300w, /wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-e1459094494609-400x305.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11438" class="wp-caption-text">Feature Selection Installation Center SQL Server</p></div>
<p>Now Uncheck the selection <em>PolyBase query service for external data</em>.</p>
<div id="attachment_11439" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116.png"><img decoding="async" aria-describedby="caption-attachment-11439" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116.png" alt="Feature Selection Installation Center SQL Server Uncheck Polybase Query Service" width="650" height="490" class="size-full wp-image-11439" srcset="/wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116.png 650w, /wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116-300x226.png 300w, /wp-content/uploads/2016/03/Feature-Selection-Installation-Center-SQL-Server-Uncheck-Polybase-Query-Service-e1459094635116-400x302.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11439" class="wp-caption-text">Feature Selection Installation Center SQL Server Uncheck Polybase Query Service</p></div>
<p>Now you can go ahead and click next. At last, you will get the success message.</p>
<div id="attachment_11440" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394.png"><img decoding="async" aria-describedby="caption-attachment-11440" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394.png" alt="Installation Center SQL Server Success" width="650" height="489" class="size-full wp-image-11440" srcset="/wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394.png 650w, /wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394-300x226.png 300w, /wp-content/uploads/2016/03/Installation-Center-SQL-Server-Success-e1459094750394-400x301.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11440" class="wp-caption-text">Installation Center SQL Server Success</p></div>
<p>Hooray, we have successfully installed our new version of SQL Server. That&#8217;s fantastic right? Have a happy coding.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/rule-oracle-jre-7-update-51-64-bit-or-higher-is-required-for-polybase-failed/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
