<?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>&#60;jco-blog&#047;&#62; &#187; Uncategorized</title>
	<atom:link href="http://www.elementalp.com/blog/index.php/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.elementalp.com/blog</link>
	<description>Software Development Project Notes</description>
	<lastBuildDate>Tue, 05 Jan 2016 18:59:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>SQL CMD</title>
		<link>http://www.elementalp.com/blog/index.php/2015/06/24/sql-cmd/</link>
		<comments>http://www.elementalp.com/blog/index.php/2015/06/24/sql-cmd/#comments</comments>
		<pubDate>Wed, 24 Jun 2015 20:16:34 +0000</pubDate>
		<dc:creator><![CDATA[ЈЦЅГЇП €ΘΘΚ]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.elementalp.com/blog/?p=247</guid>
		<description><![CDATA[SQL CMD tokens are replaced with their literal values prior TSQL parsing, so they can be used in places where a @ variable wouldn&#8217;t be permitted. Typically used for running queries within the SQL Server Management Studio, but such queries can be processed externally by calling SQLCMD.EXE (C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\SQLCMD.EXE). The literals are [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>SQL CMD tokens are replaced with their literal values prior TSQL parsing, so they can be used in places where a @ variable wouldn&#8217;t be permitted. Typically used for running queries within the SQL Server Management Studio, but such queries can be processed externally by calling SQLCMD.EXE (C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\SQLCMD.EXE). The literals are not scoped by GO statements like an @ variable and they can be re-defined later in the TSQL</p>
<p><strong>Enable SQL CMD processing from the SQL Server Management Studio</strong></p>
<p><a href="http://www.elementalp.com/blog/wp-content/uploads/2015/05/EnableSQLCmdMode.png"><img class="alignnone size-full wp-image-245" src="http://www.elementalp.com/blog/wp-content/uploads/2015/05/EnableSQLCmdMode.png" alt="EnableSQLCmdMode" width="760" height="442" /></a></p>
<p><strong>Example SQL</strong></p><pre class="crayon-plain-tag">:setvar DB "ADatabase"
:setvar NUMBER "10"

select top $(NUMBER) * from [$(DB)].sys.tables order by name
go
:setvar DB "AnotherDatabase"
select top $(NUMBER) * from [$(DB)].sys.tables order by name</pre><p></p>
<p><strong>Example C# &#8211; Using SQLCMD.EXE to run scripts</strong></p>
<p></p><pre class="crayon-plain-tag">private bool processExited = true;
private StringBuilder sqlCmdStdError = null;
private StringBuilder sqlCmdStdOutput = null;
        
private void ExecuteScriptFileViaSqlCmdUtility(string connectionString, string scriptPath, string outputPath)
{
  const string exe = "sqlcmd.exe"; //C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\SQLCMD.EXE
  try
  {
      // open the sql script file
      SqlConnectionStringBuilder ssb = new SqlConnectionStringBuilder(connectionString);

      System.Diagnostics.Debug.Write(string.Format("\t\t\tConnection = '{0}.{1}'", ssb.DataSource, ssb.InitialCatalog));
      string arguments = String.Format("-b {0} {1} -S {2} -d {3} -I -r1 -i \"{4}\"", //-o \"{5}\"
          !string.IsNullOrEmpty(ssb.UserID) ? "-U " + ssb.UserID : null,
          !string.IsNullOrEmpty(ssb.Password) ? "-P " + ssb.Password : null,
          ssb.DataSource,
          ssb.InitialCatalog,
          scriptPath,
          outputPath);

      using (Process proc = new Process())
      {
          string sqlout = string.Empty;
          proc.StartInfo.FileName = exe; 
          proc.StartInfo.Arguments = arguments;
          proc.StartInfo.UseShellExecute = false;
          proc.StartInfo.RedirectStandardOutput = true;
          proc.StartInfo.RedirectStandardError = true;
          proc.StartInfo.CreateNoWindow = true;
          proc.Exited += new EventHandler(ProcessExited);
          proc.EnableRaisingEvents = true;
          processExited = false;
          proc.OutputDataReceived += (sender, args) =&gt; WriteStdOutput(args.Data);
          proc.ErrorDataReceived += (sender, args) =&gt; WriteStdError(args.Data);
          proc.Start();
          proc.BeginOutputReadLine();
          proc.BeginErrorReadLine();

          // Synchronously read the standard output of the spawned process.
          if (!proc.WaitForExit(2000))
          {
              while (true)
              {
                  if (proc == null || proc.WaitForExit(100) || processExited) break;
              }
          }
          bool hasExited = proc.HasExited;

          int code = proc.ExitCode;
          proc.Close();

          if (sqlCmdStdOutput != null)
          {
              string results = sqlCmdStdError.ToString();
              if (!string.IsNullOrEmpty(results))
              {
                  System.Diagnostics.Debug.Write("\r\n\r\n\r\n[BEGIN SQL OUTPUT RESULT = '{0}']\r\n\r\n\r\n");
                  System.Diagnostics.Debug.Write(string.Format(results));
                  System.Diagnostics.Debug.Write("\r\n\r\n\r\n[END SQL OUTPUT RESULT = '{0}']\r\n\r\n\r\n");
              }
          }

          if (sqlCmdStdError != null)
          {
              string errors = sqlCmdStdError.ToString();
              if (!string.IsNullOrEmpty(errors))
              {
                  if (Regex.IsMatch(errors, "Msg .*, Level .*, State .*, Server .*")
                      || errors.IndexOf("Error") &gt;= 0
                      || errors.IndexOf("Invalid") &gt;= 0)
                  {
                      System.Diagnostics.Debug.Write("\r\n\r\n\r\n[BEGIN SQL ERROR RESULT = '{0}']\r\n\r\n\r\n");
                      System.Diagnostics.Debug.Write(string.Format(errors));
                      System.Diagnostics.Debug.Write("\r\n\r\n\r\n[END SQL ERROR RESULT = '{0}']\r\n\r\n\r\n");
                      throw new Exception(errors);
                  }
              }
          }
      }
  }
  catch (Exception ex)
  {
      throw new Exception(string.Format("Execute script file (via SqlCmd) failed @ '{0}'.\n\nError = {1}.\n\n", scriptPath, ex.Message), ex);
  }
}

void WriteStdError(string content)
{
  if (sqlCmdStdError == null) sqlCmdStdError = new StringBuilder();
  sqlCmdStdError.Append(content);
}

void WriteStdOutput(string content)
{
  if (sqlCmdStdOutput == null) sqlCmdStdOutput = new StringBuilder();
  sqlCmdStdOutput.Append(content);
}

private void ProcessExited(Object source, EventArgs e)
{
  processExited = true;
}</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elementalp.com/blog/index.php/2015/06/24/sql-cmd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resume Gems</title>
		<link>http://www.elementalp.com/blog/index.php/2015/06/02/resume-gems/</link>
		<comments>http://www.elementalp.com/blog/index.php/2015/06/02/resume-gems/#comments</comments>
		<pubDate>Tue, 02 Jun 2015 18:22:05 +0000</pubDate>
		<dc:creator><![CDATA[ЈЦЅГЇП €ΘΘΚ]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.elementalp.com/blog/?p=226</guid>
		<description><![CDATA[&#8220;Abstracted use case specific UML by implementing Java API used by the UI layer.&#8221; The candidate could not explain what he meant by this statement and, since 2004, he has been periodically reminded of this. Yes, we hired him, yes it was the right choice. I am still receiving his paycheck garnishments. &#8220;Please kindly do the needful&#8221; The [&#8230;]]]></description>
				<content:encoded><![CDATA[<h3>&#8220;Abstracted use case specific UML by implementing Java API used by the UI layer.&#8221;</h3>
<p>The candidate could not explain what he meant by this statement and, since 2004, he has been periodically reminded of this. Yes, we hired him, yes it was the right choice. I am still receiving his paycheck garnishments.</p>
<h3>&#8220;Please kindly do the needful&#8221;</h3>
<p>The end of a cover letter from a person in India answering a posting for a local-only position. This became our team&#8217;s mantra for several years and is now a part of our regular language.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elementalp.com/blog/index.php/2015/06/02/resume-gems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Miscellaneous stuff (that I can&#8217;t remember)</title>
		<link>http://www.elementalp.com/blog/index.php/2015/05/26/stuff-that-i-cant-seem-to-remember/</link>
		<comments>http://www.elementalp.com/blog/index.php/2015/05/26/stuff-that-i-cant-seem-to-remember/#comments</comments>
		<pubDate>Tue, 26 May 2015 23:22:31 +0000</pubDate>
		<dc:creator><![CDATA[ЈЦЅГЇП €ΘΘΚ]]></dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.elementalp.com/blog/?p=175</guid>
		<description><![CDATA[C# Convert string array to string [crayon-6a06f744c8ed7535909817/] result = HelloDoctorNameContinueYesterdayTomorrow result2 = Hello, Doctor, Name, Continue, Yesterday, Tomorrow Format Decimal as currency [crayon-6a06f744c8f34281170680/] result = $32.95 Format Decimal as string with N places [crayon-6a06f744c8f85931621056/] Optionally Running Debug Code [crayon-6a06f744c8fd5773518644/] SQL Generate Sequential Guids arguably not the most commonly used capability, but here it is&#8230; [crayon-6a06f744c902a850477894/] [&#8230;]]]></description>
				<content:encoded><![CDATA[<h1>C#</h1>
<p><strong>Convert string array to string</strong></p><pre class="crayon-plain-tag">var array = new string[]{&quot;Hello&quot;,&quot;Doctor&quot;,&quot;Name&quot;,&quot;Continue&quot;,&quot;Yesterday&quot;,&quot;Tomorrow&quot;};
string result = string.Join(string.Empty, array);
string result2 = string.Join(&quot;, &quot;, array);</pre><p>result = HelloDoctorNameContinueYesterdayTomorrow<br />
result2 = Hello, Doctor, Name, Continue, Yesterday, Tomorrow</p>
<p><strong>Format Decimal as currency</strong></p><pre class="crayon-plain-tag">decimal amount = 32.95M;
var result = string.Format(&quot;{0:C}&quot;, amount);}</pre><p>result = $32.95</p>
<p><strong>Format Decimal as string with N places</strong></p><pre class="crayon-plain-tag">public string FormatAsDecimalString(decimal? value, int places = 2)
{
        if (value == null) value = 0;
        if (places &amp;gt;= 0) places = 2;
        return String.Format(&quot;{0:N&quot; + places.ToString() + &quot;}&quot;, value);
}</pre><p><strong>Optionally Running Debug Code </strong></p><pre class="crayon-plain-tag">public void DoSomething()
{
   if (System.Diagnostics.Debugger.IsAttached)
   {
      //called only when debugger is attached
   }

   DoSomethingDebuggey();
}

//called only when set to debug build
[Conditional(&quot;DEBUG&quot;)]
private void DoSomethingDebuggey();
{
}</pre><p></p>
<h1>SQL</h1>
<p><strong>Generate Sequential Guids</strong><br />
arguably not the most commonly used capability, but here it is&#8230;</p><pre class="crayon-plain-tag">declare @tab table ([id] uniqueidentifier default newsequentialid(), [dummy] bit)
declare @generate int = 50
declare @count int = 1
while(@count &amp;lt;= @generate)
begin
	insert @tab ([dummy]) values (1)
	set @count = @count + 1
end
select [id] from @tab order by [id]</pre><p><strong>Print immediately to the Messages window when running queries in SQL Management Studio</strong></p><pre class="crayon-plain-tag">declare @message nvarchar(1000);
set @message = '...something, something, something, dark side...'
raiserror (@message, 0, 1) with nowait --print immediately (doesn't interrupt query flow)</pre><p><strong>Delete temp table if exists</strong></p><pre class="crayon-plain-tag">if (object_id('tempdb..#temp') is not null) drop table #temp</pre><p><strong>SQL Server database stuck in &#8220;Restoring&#8221; state</strong></p><pre class="crayon-plain-tag">use master;
RESTORE DATABASE [DatabaseNameHere] WITH RECOVERY</pre><p><strong>Disable / Enable triggers and constraints for the database</strong></p><pre class="crayon-plain-tag">--disable
exec sp_MSforeachtable 'alter table ? disable trigger all;
alter table ? nocheck constraint all;'

--enable
exec sp_MSforeachtable 'alter table ? enable trigger all;
alter table ? check constraint all;'</pre><p><strong>Clear the cache without re-starting</strong></p><pre class="crayon-plain-tag">DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE</pre><p><strong>Check if file exists using T-SQL</strong><br />
Note: The identity under which the SQL Server process is running will require permissions to read the file system. Right-click the folder/file from file explorer, from the &#8220;Security&#8221; tab, assign appropriate permissions to &#8220;NetworkService&#8221; (or whatever credential SQL Server is using). <em>Don&#8217;t forget to remember not to forget to remember that the file system is seen from the perspective of the SQL Server!<br />
</em></p><pre class="crayon-plain-tag">create function [dbo].[SIP_NPT_fFileExists](@path varchar(512))
returns bit
as
begin
     declare @result int
     exec master.dbo.xp_fileexist @path, @result output
     return cast(@result as bit)
end</pre><p><strong>Close all database connections</strong><br />
<a href="http://www.elementalp.com/blog/index.php/2015/06/24/sql-cmd/">Using setvar in T-SQL </a></p><pre class="crayon-plain-tag">:setvar DB &quot;MyDb&quot;
alter database [$(DB)] set single_user with rollback immediate
alter database [$(DB)] set multi_user</pre><p></p>
<h1>Other</h1>
<p><strong>Excel 2013 Cell Limit</strong><br />
Cell <span style="color: #0000ff;"><strong>XFD1048576</strong></span> is the max cell in Excel. It&#8217;s &#8220;right down&#8221; there.<br />
That&#8217;s 16,383 columns x 1,048,576 rows.<br />
<a href="http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HA103980614.aspx" target="_blank">excel-specifications-and-limits</a></p>
<p><strong>Excel Guid Formula</strong><br />
=CONCATENATE(DEC2HEX(RANDBETWEEN(0,4294967295),8),&#8221;-&#8220;,DEC2HEX(RANDBETWEEN(0,65535),4),&#8221;-&#8220;,DEC2HEX(RANDBETWEEN(16384,20479),4),&#8221;-&#8220;,DEC2HEX(RANDBETWEEN(32768,49150),4),&#8221;-&#8220;,DEC2HEX(RANDBETWEEN(0,65535),4),DEC2HEX(RANDBETWEEN(0,4294967295),8))</p>
<p><strong>Remove hiberfil.sys from a server</strong><br />
If it&#8217;s a Citrix VM, hibernation must first be enabled in the &#8220;firmware&#8221; by issuing the following command, and re-start the VM.</p>
<p><code class="EnlighterJSRAW" data-enlighter-language="generic">xe vm-param-add uuid=&lt;your VM&gt; param-name=platform acpi_s4=true</code></p>
<p>Run the command interpreter &#8220;Run as Administrator&#8221; and enter:<br />
<code class="EnlighterJSRAW" data-enlighter-language="generic">powercfg -h off </code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.elementalp.com/blog/index.php/2015/05/26/stuff-that-i-cant-seem-to-remember/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moved from a broken BlogEngine to a working WordPress installation&#8230;</title>
		<link>http://www.elementalp.com/blog/index.php/2015/05/22/hello-world/</link>
		<comments>http://www.elementalp.com/blog/index.php/2015/05/22/hello-world/#comments</comments>
		<pubDate>Fri, 22 May 2015 22:14:57 +0000</pubDate>
		<dc:creator><![CDATA[ЈЦЅГЇП €ΘΘΚ]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.elementalp.com/blog/?p=1</guid>
		<description><![CDATA[My ISP upgraded the site from MS Server 2003 \ IIS 6 to MS Server 2012 \ IIS 8. That&#8217;s great, but it broke my old BlogEngine. I&#8217;ll be re-creating [from backups] such gems as the largest Excel cell address, and the best ending comment for a SQL stored procedure. They aren&#8217;t a great loss, but I miss them.]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.elementalp.com/blog/wp-content/uploads/2015/05/cropped-ThisJustIn.png"><img class="alignnone size-medium wp-image-16" src="http://www.elementalp.com/blog/wp-content/uploads/2015/05/cropped-ThisJustIn-300x38.png" alt="cropped-ThisJustIn.png" width="300" height="38" /></a></p>
<p>My ISP upgraded the site from MS Server 2003 \ IIS 6 to MS Server 2012 \ IIS 8. That&#8217;s great, but it broke my old BlogEngine. I&#8217;ll be re-creating [from backups] such gems as the largest Excel cell address, and the best ending comment for a SQL stored procedure.</p>
<p>They aren&#8217;t a great loss, but I miss them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elementalp.com/blog/index.php/2015/05/22/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
