How to make the Microsoft sqlsrv driver for PHP ignore text returned from the database

Ta-da:

sqlsrv_configure(‘WarningsReturnAsErrors’,0);

Share on Facebook

How to reset a Cisco ASA 5505 to factory defaults via console

I don’t often need to reset a Cisco ASA 5505 to factory defaults, but when I do, it’s a giant pain in the ass. I won’t go into the details of what each command does, but rest assured that following this guide will reset your ASA to defaults.

 Share on Facebook

Create a table variable of dates within a range

Whether to iterate through them, or join to the table, sometimes a table containing nothing but dates within a specific range comes in handy. Here’s my code snippet for creating such a table:

 

This will yield a table of these values (thru the @endDate):

 

This can also be modified to dateadd() by month, week, etc.. or use a dynamic date range by changing the @startDate and @endDate to calculated dates instead of static values.Share on Facebook

Error 403.14 when publishing ASP.Net MVC project to IIS

I’ve run into this before and didn’t write down the solution, and I just spent another 4 hours trying to troubleshoot this problem for another project, so this is a note to future me.

When publishing an ASP.Net MVC application to another server on IIS, you have to right-click on the folder you’re publishing to (in IIS) and select ‘Convert to Application’ – make sure the application you specify is configured for the correct version of the .Net Framework, and you’re golden. If you forget this step, you’ll get errors like this:

Parser Error Message: Could not load type ‘myProjectNamespace.Default’

…which will just lead you to hating yourself for wasting so much time on such a dumb issue.Share on Facebook

How to bring a MSSQL database online out of standby/read-only

I run into this a lot – we have a standby/log-shipping database that’s used for reporting, but eventually we may need to bring it online and don’t have a transaction log to restore then bring it online with. Instead, just run:

…and you should be set. In some instances, depending on where your standby database originated from, you may run into errors like this one:

During startup of warm standby database DBNAME (database ID 6), its standby file (‘s:\MSSQL\DBNAME_Standby.bak’) was inaccessible to the RESTORE statement. The operating system error was ‘2(The system cannot find the file specified.)’. Diagnose the operating system error, correct the problem, and retry startup.

To get around that, run this:

And boom, your database is writable.

 Share on Facebook

How to create a unique filtered index as a substitute for unique constraints in MSSQL

You can enforce unique constraints on a column in SQL using a basic ‘create constraint’ command:

…but doing so on a column that allows null values will yield an error like the one below:

In these instances, your best bet is a unique filtered index. There’s some pretty in-depth info from Redgate on the subject, but the syntax is pretty similar to creating a normal nonclustered index, just with the addition of a filter and unique clause:

And voila – success:

Share on Facebook

How to kill all open connections on a database in MSSQL

This handy script will kill all open connections to a database. Handy if you need to take it offline and someone just won’t let it die.

 

 Share on Facebook

Variable reference for common date calculations

I spend a good portion of a typical workday writing T-SQL code. Often enough, I need to calculate a date variable based on the current date. Here’s my reference scratch for some commonly used date calculations.

Share on Facebook

PHP Manager Fails to install on Windows 2016

Most of my web-dev projects are PHP based, and most of the data I work with is in MSSQL, so I end up using a combination of IIS + PHP + MSSQL pretty often. I just spun up my first Windows 2016 server, and promptly encountered issues installing PHP using Microsoft’s own Web Platform Installer tool (even using the latest version; 5.0 as of this writing). I was able to get PHP and the SQL drivers to install, but PHP Manager kept failing.

The fix: Change the registry key below from the default decimal value of 10 to a lower value; changing to 9 worked for me. Close regedit, re-run WPI and the installation will complete successfully. Go back into regedit and change the value back to 10 to prevent issues with future installations/updates of other IIS related apps that might check that value.

Edit: also make sure you have .Net 3.5 installed. WPI doesn’t prompt for it as a dependency, but the PHP Manager install will fail without it.

Edit v2: Apparently WPI should no longer be trusted for installing PHP Manager for IIS. Grab the MSI file for your version of IIS from this Git repo: https://github.com/edgardo001/PHPManagerForIIS-Versiones.Share on Facebook

Configuring IIS to get around CORS errors when setting up a CDN site

I’m starting to use a lot of shared libraries in my projects (JQuery, Font Awesome, Bootstrap, etc…). Rather than have a ton of copies floating around on my dev machine, and rather than use public content delivery networks (CDNs), I setup my own so I can throw whatever I want onto that host. But, there’s a catch. In the interest of security and preventing cross-site scripting attacks, IIS doesn’t want to cough up files from the domain it’s configured for when the browser is pulling content using a different hostname. For example: the site in my browser is http://mysite.com, but my personal CDN is http://cdn.mysite.com – they’re totally separate sites in IIS, and could potentially be on separate servers.

If you look in the DevTools menu (F12) within Chrome, you’ll see an error like this:

Access to Font at ‘http://cdn.mysite.com /font-awesome/fonts/fontawesome-webfont.woff2?v=4.5.0’ from origin ‘http://mysite.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://mysite.com’ is therefore not allowed access.

To set your IIS configuration to allow this, open IIS Manager > Browse to your site > HTTP Response Headers > Add > (Enter the info below) > click OK > Restart IIS (restart might not be necessary).

In reality, you should NOT leave an asterisk in there for a production environment. List the hostname you’ll be allowing access from. I’m told there’s no mechanism to allow multiple hostnames without some URLRewrite voodoo. I’m leaving an asterisk for now since it’s my dev laptop and it’s firewalled off anyway.

Note: I continued to get this error in Chrome and messed with it for the better part of an hour. In the end, it appears that Chrome was still caching the old responses and it just took a long time for me to realize I needed to clear my cache. Or maybe me screwing around with MIME types for the .woff files is what did it, even though reverting the change didn’t re-break it. Who knows.

 Share on Facebook