Friday, October 30, 2015

Executing the Same SQL Statement on ALL SQL Databases

From time to time you may need to execute the same SQL Statements on ALL SQL Databases on your Server. Better yet, you may even need to have the Database Names to match a specific pattern.

There are two ways to accomplish this:

1 - Using sp_MSforeachdb - This is a hidden Microsoft SQL feature that loops through all databases for you and allows you do execute a query on each database.



2 - Using a Cursor in a While Loop - This is essentially the old fashion way, by looping through all the databases using a loop and executing the command.



In the above code:

DB_Pattern - Partial String you want to find in the database name.
TABLENAME - Name of the Table you want to get a count from.
DB_Name - Variable that stores the Database Name

Comments or questions? Post them below.

Thanks,

Pete Soheil
DigiOz Multimedia, Inc.
www.digioz.com



Monday, August 31, 2015

Enable or Disable Local User Account on Windows 10 Home Edition

I am often amazed by some of the changes that Microsoft makes to various versions of their Operating System, and Windows 10 is sadly no exception. Suppose that you have installed Windows 10 Home Edition on your Computer and that you wish to temporarily "Disable" (NOT Remove) a User Account on your PC.

As of right now there is no way to do this through any User Interface on Windows 10 Home Edition. To disable an User Account, do the following:


  1. Right-Click on the Start Menu, then choose "Run". 
  2. Type "cmd" and press enter to run command prompt. 
  3. Right click on the Command Prompt Icon in the Taskbar, and choose "Run as Administrator". 
  4. Enter the following command and hit ENTER to disable the account in question:
          net user USERNAME /active:no

Here "USERNAME" is the actual you with to disable. For example if you have a User Account called "Joe" you would run this command:

          net user Joe /active:no

To enable the account again, run the following:

          net user USERNAME /active:yes

I have no idea what removing this feature accomplishes for Microsoft, other then annoying the crap out of Administrators, but here is a way around it in case anyone needs it. 

Saturday, August 16, 2014

A script to drop all tables and their content, views and stored procedures in MS SQL

Occasionally as a developer you may encounter a case where you want to completely remove all tables, views and stored procedures in a database without removing the system tables, system views and system stored procedures or without having to delete the database as a whole and recreating it.

One way is to right-click on each table one by one and try to delete them, only to find out that a foreign key constraint prevents you from doing so, at which time you have to try and figure out how each table relates to the other, and remove them in the correct sequence. If you have a few hundred or even thousand database objects this could take a long time!

Fear not, because we finally have a solution for this! The script below will take care of this for you in one shot and give you a clean database to work with.


Wednesday, December 4, 2013

Formatting Large Hard Drive (greater than 32 GB) with Fat 32 to work with both Mac and Windows

If you are a user who uses both a Mac and a PC (OSX and Windows) you may come across a scenario where you need to use an external Hard Drive for both Operating Systems to backup and transfer files between the two. Most external Hard Drives are formatted in the Windows NTFS file system format, and unfortunately Mac OSX only allows you to read files from NTFS, but you cannot write files to NTFS.

Some solutions for this problem include the purchasing of a software that converts files and folders to NTFS as you attempt to copy them to the external Hard Drive, the most notable one out there is Paragon NTFS for Mac OS X which at the time of this writing supports OS X 10.9 Mavericks already! Of course the software does cost $19.95, and may therefore not be an option for some users. 

A much simpler solution is to format the Hard Drive using the Fat32 file system format which all Mac OS X versions already support. The problem that most users run into when they attempt to format an external Hard Drive larger than 32 GB is that the built in Windows Disk Manager does not support it. 

An easy solution to this problem is to use a Disk Utility Software such as Seagate Disk Wizard. This utility is FREE if you have at least 1 Seagate Hard Drive on your sytem, but you have to purchase the professional version if you do not. If that is not the case for you, you can use a similar tool called "AOMEI Partition Assitant" to do the same.

For Seagate Disk Wizard, you can follow the steps below to do this:

  1. Install and Launch the Seagate Disk Wizard by downloading it from HERE for free and running the executable. 
  2. Select "Add New Disc" to do a simple partitioning and formatting.

  3. Select the correct disk and follow the wizard prompts. 
  4. Select MBR or GPT. MBR is recommended for partitions smaller than 2 TB.
  5. Select the Unallocated disk and then Create new partition.
  6. Change the File system: to FAT32. If you prefer, you may manually select the partition letter and add a label. Select Accept.
  7. DiscWizard will display its progress.
  8. Select OK when complete.
That's all you need to do! Now you can plug your external USB Drive into both a Mac and PC and read and write from both operating system.

NOTE: Another small point to keep in mind is that if your Disk Space is larger then 3TB in size, in order to have the whole disk as 1 partition it will have to be GPT, not MBR. Otherwise you will have to create multiple partitions.

To convert from MBR to GPT, do the following:

1. Open a command prompt on your windows Operating System.
2. Type "diskpart" and press enter.
3. Type "list disk" to see a list of disks on your system.
4. Enter "select disk #" where "#" is the Disk Number from the list provided.
5. Type "convert gpt" to convert the disk to GPT. 

I hope this helps others looking for an easy solution. Feel free to leave any comments or questions you may have. 

Thanks,
Pete Soheil
DigiOz Multimedia, Inc.

Saturday, November 23, 2013

Joomla 2.5 and 3.0 Recaptcha Plugin Suddenly Not working!

We have been using the Recaptcha Plugin on all our Joomla Sites to filter out spam registrations on the sites, and up until last week everything was working without any issues. Last week however all of the sudden ALL Recaptcha Plugins on ALL our Joomla Sites stopped working at the same time.

After some head scratching, we came across the following announcement by the Google Recaptcha Team, which basically said the Recaptcha URL's have all changed. 

To their credit they did announce the change, but they announced it in a Google Group that no one ever checks or reads! This should have been front page news on the Recaptcha Home Page.

To put this in terms everyone understands, here is basically what you have to do to get your Joomla Recaptcha working again:


  1. Go to "/plugins/captcha/recaptcha" folder of your Joomla installation, and open the file "recaptcha.php". 
  2. In the file, find this code block:
  3. const RECAPTCHA_API_SERVER = "http://api.recaptcha.net";
    const RECAPTCHA_API_SECURE_SERVER = "https://www.google.com/recaptcha/api"; 
    const RECAPTCHA_VERIFY_SERVER = "api-verify.recaptcha.net";
    
    Replace it with this:
    const RECAPTCHA_API_SERVER = "http://www.google.com/recaptcha/api";
    const RECAPTCHA_API_SECURE_SERVER = "https://www.google.com/recaptcha/api"; 
    const RECAPTCHA_VERIFY_SERVER = "www.google.com";
    
  4. Next, find line 118, which looks like this:

    $response = $this->_recaptcha_http_post(self::
    RECAPTCHA_VERIFY_SERVER, "/verify",
    

    And replace it with this:

    $response = $this->_recaptcha_http_post(self::
    RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
    

That's all you have to do to get things back up and working! Credit for this fix goes to "SniperSister" on Github who posted this solution in THIS GIT Commit as well as THIS Bug Ticket he opened on JoomlaCode.

Enjoy!
Pete Soheil
DigiOz Multimedia, Inc.
www.digioz.com

Saturday, August 24, 2013

iPhone is disabled try again in 22,955,128 minutes!

From time to time you may enter your iPhone, iPad or iPod lock screen password wrong. The first few times you enter it wrong, you will get an error message like this:



If you keep trying and enter it wrong every time, you will get this screen:


If you still keep trying, and really piss the phone off, you may get this screen after a few attempts:


In case you are wondering, that's 44 years! While I understand the message, I wonder what Apple was thinking when they created this system. Surely they didn't expect people to wait that long to use their phone again! 

The good news is, you won't have to wait for 44 years to use your phone again. The bad news however is that you may or may not lose all your files and apps depending if you regularly back up your phone to either iCloud or your PC. 

How to fix this mess:

Case 1: If you have previously synced your device with iTunes:
    • You may be able to reset the passcode by restoring the device. To do so, do the following:
      • Connect the device to the computer with which you normally sync and open iTunes. Note, that if iTunes prompts you to enter the passcode, try another computer that you have synced with. 
      • Right-click the device in the left column and select Back up.
      • When the backup is complete, select Restore.
      • When finished, restore from your most recent backup.

Case 2: If you have never synced your device with iTunes, and don't have it backed up to iCloud:
    • Connecting the device may result in this error message: "iTunes could not connect to the [device] because it is locked with a passcode. You must enter your passcode on the [device] before it can be used with iTunes." You have pretty much lost all your content and apps at this point, but can still use the phone by wiping everything out and bringing it to the factory setting. To do so, do the following:
      • Disconnect the USB cable from the device, but leave the other end of the cable connected to your computer's USB port.
      • Turn off the device: Press and hold the Sleep/Wake button for a few seconds until the red slider appears, then slide the slider. Wait for the device to turn off.
      • While pressing and holding the Home button, reconnect the USB cable to the device. The device should turn on.
      • Continue holding the Home button until you see the "Connect to iTunes" screen. When this screen appears, release the Home button.
      • iTunes should alert you that it has detected a device in recovery mode. Click OK, and then click Restore to restore the device.

Case 3: If you have never synced your device with iTunes, but DO have it backed up to iCloud:
    • Follow the steps outlined in Case 2 above to wipe out your phone and re-install the factory software and setting. 
    • Once this is done, in the welcome screen chose "Restore from iCloud" and follow the on screen instructions to restore all your content and apps to their previous state, which means you get all your stuff back to the point you backed up to the cloud. So depending on when you last backed up to the iCloud you may only lose a few days worth of stuff. 

I hope this information comes in handy for someone. Feel free to leave any comments or questions you may have below.

Thanks,
Pete Soheil
DigiOz Multimedia, Inc.
www.digioz.com

Friday, June 7, 2013

Visual Studio 2012 Freezes or Crashes When trying to add a new ASP.NET MVC Controller

Occasionally while you are working on an ASP.NET MVC Project when you right-click on the Controller folder and choose "Add > Controller", you may notice that Visual Studio 2012 is hanging indefinitely or freezes up to the point you have to kill the "devenv.exe" Process through the Task Manager, only to find out that no matter how many times you repeat this cycle you are still not able to add Controllers in this manner. What makes it even more puzzling is that you can easily do the same with other ASP.NET MVC Project without any issues!

This issue has been reported to Microsoft over and over without them offering much of a solution:

http://connect.microsoft.com/VisualStudio/feedback/details/717662/visual-studio-consistently-freezes-after-opening-solution-and-after-debugging

http://connect.microsoft.com/VisualStudio/feedback/details/763452/vs2012-hangs-on-add-controller-when-project-originated-from-vs2010-express

Some workarounds suggested by various Developers are as follows:

  • You can also create a new solution in VS2012, then import all of the existing code files from the original solution. Add => Controller... will then start functioning properly again.
  • Select Add => New Item from the context menu, then choose MVC 4 Controller. However, you don't get any of the scaffolding that you do with the wizard.
  • Run devenv.exe /resetskippkgs http://msdn.microsoft.com/en-us/library/ms241276(v=vs.100).aspx
  • Disable "Visual Studio Hosting Process" in each executable project's properties (build tab, all the way at the bottom)
  • Disable Intellitrace on Debug in Tools, Options, Intellitrace 
None of the above solutions however address the actual reason that causes this problem, and no it is not a Visual Studio bug but an Operating System behavior that causes this issue. The issue is caused by the Automatic File Block feature that was adding by Microsoft in recent years. Basically, any time you download or copy files and/or folders from the web or an un-trusted source Windows automatically blocks that file or folder. If you right click on the file in question, you will see the following:


Here is a list of ways your file may get blocked:
  • Your Project is under CVS, SVN, Git or Mercurial Source Control, and you just fetched the latest version of the Project from that Source Control.
  • You downloaded the project from the WWW through a list file and extracted it, then ran the Solution File. 
  • You copied the files from a Network Location that is NOT Trusted by your PC.
All you have to do to unblock the files and folders is to click on the "Unblock" button shown in this dialog, which you can get to by right-clicking on the file and choosing "Properties" in File Explorer. Ideally you want to unblock all files and folders in your project, but the important ones are:
  • /packages/EntityFramework.5.0.0 (or whatever version you are using) recursively
  • Your Project's ".sln", ".suo", ".v11.suo", ".csproj", ".csproj.user".
  • All assemblies inside the "bin" folder.
  • The "Controllers" folder and all Controller Class files inside it. 
Make sure Visual Studio is closed and exited completely before doing this. By doing so you should be able to Add Controllers in the above manner again. 

Comments, suggestions, concerns? Leave them down below. 

Thanks,
Pete Soheil
DigiOz Multimedia, Inc.