Repair Microsoft SQL database/table lessons.

I was getting the following kinds of errors after an errant update to a Microsoft SQL Server (2005 in this case) while running a “DBCC CHECKDB”:

DBCC results for ‘Transactions’.
Msg 8928, Level 16, State 1, Line 1
Object ID 37575172, index ID 0, partition ID 72057594038845440, alloc unit ID 72057594042843136 (type In-row data): Page (1:1169) could not be processed. See other errors for details.
Msg 8939, Level 16, State 98, Line 1
Table error: Object ID 37575172, index ID 0, partition ID 72057594038845440, alloc unit ID 72057594042843136 (type In-row data), page (1:1169). Test (IS_OFF (BUF_IOERR, pBUF->bstat)) failed. Values are 29493257 and -4.
Msg 8928, Level 16, State 1, Line 1
Object ID 37575172, index ID 0, partition ID 72057594038845440, alloc unit ID 72057594042843136 (type In-row data): Page (1:1309) could not be processed. See other errors for details.
Msg 8939, Level 16, State 98, Line 1
Table error: Object ID 37575172, index ID 0, partition ID 72057594038845440, alloc unit ID 72057594042843136 (type In-row data), page (1:1309). Test (IS_OFF (BUF_IOERR, pBUF->bstat)) failed. Values are 29493257 and -4.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1337), slot 12 should be pointed to by forwarding row page (1:1169), slot 20. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1337), slot 38 should be pointed to by forwarding row page (1:1169), slot 32. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1337), slot 41 should be pointed to by forwarding row page (1:1169), slot 41. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 5 should be pointed to by forwarding row page (1:1169), slot 45. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 7 should be pointed to by forwarding row page (1:1309), slot 43. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 23 should be pointed to by forwarding row page (1:1169), slot 56. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 24 should be pointed to by forwarding row page (1:1169), slot 59. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 29 should be pointed to by forwarding row page (1:1169), slot 62. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1338), slot 33 should be pointed to by forwarding row page (1:1309), slot 66. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1339), slot 25 should be pointed to by forwarding row page (1:1309), slot 38. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1340), slot 17 should be pointed to by forwarding row page (1:1309), slot 51. Did not encounter forwarding row. Possible allocation error.
Msg 8994, Level 16, State 1, Line 1
Object ID 37575172, forwarded row page (1:1340), slot 20 should be pointed to by forwarding row page (1:1309), slot 22. Did not encounter forwarding row. Possible allocation error.
There are 49003 rows in 821 pages for object “Transactions”.
CHECKDB found 0 allocation errors and 16 consistency errors in table ‘Transactions’ (object ID 37575172).

Here is what I did/tried and what eventually worked:

Put the database in single user mode:

ALTER DATABASE databasename SET SINGLE_USER

Examined and saved some of the contents of a corrupt page:

DBCC PAGE (‘tablename’, 1, pagenumber, 3) WITH TABLERESULTS

Tried to rebuild the indexes in the corrupt table:

DBCC DBREINDEX (“tablename”, ” “, 70)

Tried to repair the database without data loss:

DBCC CHECKDB(‘databasename’, REPAIR_REBUILD)

Eventually gave in and repaired the database with possible data loss:

DBCC CHECKDB(‘databasename’, REPAIR_ALLOW_DATA_LOSS);

Enabled multi-user mode:

ALTER DATABASE databasename SET MULTI_USER

Fortunately, it doesn’t look like much data was lost, since there was no backup.

Upgrading from Windows 2003 ADS to Windows 2012 R2

Initially, I tried to bring a Windows 2012 R2 into the 2003 ADS environment directly. In other words, I installed 2012 server and tried to promote it in an environment with 2003 DCs exclusively. This failed miserably and instead of spending a lot of time trying to figure the issue out, I opted to go to 2008 R2 and then 2012 R2. This scenario went much smoother.

This was a single Windows 2003 domain. Very simple environment. All role installation and promotion was done from the domain Administrator account.

I built a Windows 2008 R2 server and joined it to the domain.

Then, I added the Active Directory Domain Services role, and let the wizard install the DNS Server role as well.

Once the roles were installed and server rebooted, if needed, I verified the time and that DNS was set correctly.

Then, I ran dcpromo.

When dcpromo was finished, I rebooted and logged in the domain Administrator account.

Then, I transferred all the FSMO roles to the new Windows 2008 R2 domain controller (see http://jim-zimmerman.com/?p=880 ).

I built and joined a Windows 2012 R2 server to the domain.

I added the Active Directory Domain Service role, and again let the wizard install the DNS Server role.

Once the roles were installed, and I verified the DNS and time, I ran the dcpromo equivalent in Windows 2012 R2. I clicked on the flag with the warning symbol in the top right of the Server Manager window. In the drop down, under the Active Directory Domain Services role, was a link to promote the server. I clicked on it to start the promotion. Note: dcpromo is not supported in 2012. When you try to run it, you get a message telling you to go to Server Manager.
dcpromo equiv from server manager make sure to select the 2008 server to replicate from.

After the server rebooted, I transferred all the roles, in a similar manner as above, to my Windows 2012 R2 server.

Once that was done, I verified replication and authenticated to the 2012 server from a client.

Then, I shutdown my 2003 domain controller.

In a week or maybe two, I will boot the 2003 server and demote it. I don’t want to demote right away in case something goes wrong or comes up.
demote 2003 box or shutdown for a while.

Then, I will demote the 2008 server as well. If there were more than one domain controller in this environment, I would keep the 2008 server up until all the domain controllers were replaced with upgraded ones.

UPDATE: So, I demoted the 2003 server after checking to make sure all the roles were on the 2012 server, and ensuring that the Global Catalog was on the 2012 server too. To demote, I just ran dcpromo.

Then, a couple days later, I went through the same process on my 2008 server. I ended with only one domain controller which is a Windows 2012 R2 server.

Enable automatic Administrator login – Windows server

I don’t really like to do this, but sometimes you are left with no choice. Here is how to have a Windows server automatically login to the Administrator account:

Run regedit.

Navigate to:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]

Right mouse click on Winlogon and add the following String Values with the following settings:

“AutoAdminLogon”=”1″
“DefaultUsername”=”mydomain\Administrator”
“DefaultPassword”=”mypassword”

Then, reboot.

Using DISKPART to add/format a newly added hard drive.

Used this basic procedure to add a hard drive in Windows 2012 R2 Core:

List the disks to ensure you select the correct one:

DISKPART
DISKPART> LIST DISK

Select the correct disk:

DISKPART> SELECT DISK=1

Put the disk online:

DISKPART> ONLINE DISK

Examine the disk attributes:

DISKPART> ATTRIBUTES DISK

Remove the READONLY attribute if on:

DISKPART> ATTRIBUTES DISK CLEAR READONLY

Create a primary partition on the drive:

DISKPART> CREATE PARTITION PRIMARY

Format it:

DISKPART> FORMAT

Assign the desired letter to the drive:

DISKPART> ASSIGN LETTER=D

Allow ping through a Cisco ASA

Here are the changes you need to make to allow clients on your LAN to ping through the Cisco ASA to a host on Internet/WAN. Basically, this is how to create a class map and a policy that uses the class map. Then, implement the policy.

class-map myclass
match default-inspection-traffic
exit
policy-map mypolicy
class myclass
inspect icmp
exit
service-policy mypolicy interface outside

iPhone 5s and evasi0n 7 1.0.1 lessons

Well, at least I was patient enough to wait until the panic died down about version 1.0.0 of evasi0n for IOS 7. My first attempt with 1.0.1 did not go too good. I ended up cutting my loses and restoring. I believe that part of my problem was that I did not have 7.0.4 installed. Other possible mistakes made: had the phone plugged in before firing up evasi0n, did not kill any applications, and did not restart my phone before like I ususally do. Also, I just hooked it up and went for it. As a result, I got stuck on the configuring system 2/2 portion. My response was to kill evasi0n on my computer and try again. Same thing. I rebooted the phone thinking I would definitely have to restore at this point, but I didn’t have too. I deleted the evasi0n icon, killed everything running and rebooted again. Once up, I tried again. It seemed to work this time, until it rebooted and would get stuck on the Apple screen. At this point, I had no choice but to restore. This is when I discovered that I did not have IOS 7.0.4. So, I upgraded and restored, and made sure everything checked out before I more cautiously tried again.

After I restored, I made sure I killed anything I had running/open and I rebooted. Once the phone was rebooted, I started up evasi0n (MacOS Mavericks) and then plugged in the phone. This time everything went flawlessly. When instructed by evasi0n on my computer, I hit the evasi0n icon on my phone. All went well. Note: quite a few reboots with this jailbreak (three or four if I recall).

Turns out I was still a little too early, since the Mobile Substrate had not yet been updated. As a result, pretty much nothing worked. Fortunately, Saurik quickly turned around an update to Mobile Substrate, now called Cydia Substrate. So, between that and PreferenceLoader update and the 3.0-1 update to TetherMe, it looks like I am back in business.

How to move a Windows 8 key to another machine or activate after a fresh installation.

On the old machine/installation, bring up an Administrator Command Prompt.

Enter the following to remove the product key:

slmgr.vbs -upk

From the new machine, go into Administrator Command Prompt.
Enter the following to activate the new machine by phone:

slui.exe 4

If you have already tried the Product key and got the message stating that the key can only be used once, you will be presented with a Windows with a phone number (855 toll free number), and a long string of numbers.

If you did not enter the product key, you will be prompted to Activate with a new key. I have not tested this, but I believe that you could enter your Product key. You should get an error. I would close the window, and try a “slui.exe 4″ again. I would think that would get you to the same screen.

Call the phone number.

You will be prompted to enter the long string of numbers.

Then, you will be asked for more information. I was asked how many computers the key has been used on. I answered one (the truth). I was then given a long string of numbers that I entered in the fields at the bottom of the window.

Once complete, I clicked Activate. My installation was successfully activated.

Finding/Replacing control characters in Excel.

While doing some database work, I found myself needing to replace extraneous tab characters in a couple columns in Excel. Here is how I was able to do it. This method could just as easily be applied to any other control character once you know the ASCII code.

Go into Find/Replace.

In the “Find what” field, just hold down the Alt key and enter 0009.

Release the Alt, and Find/Replace as you usually would.

This will find all the tab characters since 9 is the ASCII code for tab. You can do this for any other ASCII character as well, but I doubt that would come up very often.

MySQL ERROR 2006 – server has gone away while restoring.

I was getting the following errors when I was trying to restore a Request Tracker MySQL database in linux (Ubuntu to CentOS).

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 10
Current database: rt4

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 11
Current database: rt4

ERROR 2006 (HY000): MySQL server has gone away
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 12
Current database: rt4

These errors came later in the restore:

ERROR 1231 (42000): Variable ‘time_zone’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘sql_mode’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘foreign_key_checks’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘unique_checks’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘character_set_client’ can’t be set to the value of ‘NULL’
Query OK, 0 rows affected (0.00 sec)

ERROR 1231 (42000): Variable ‘collation_connection’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘sql_notes’ can’t be set to the value of ‘NULL’

To get the database restored, I had to change the maximum allowed packet setting.

The best way to do that is to add the following line to the [mysqld] section of the my.cnf (CentOS: /etc/my.cnf or Ubuntu: /etc/mysql/my.cnf):

max_allowed_packet = 16M

Then, restart your MySQL service.
Ubuntu: service mysql restart
CentOS: service mysqld restart

Now, I did this on both of my servers, then I could use my regular backup script and the setting would be picked up by the my.cnf. However, you can do the backup with option enabled if it is not in your my.cnf by using something like the following:

mysqldump $thedb –user=”myid” –password=”$SQLPWD” –max_allowed_packet=16M > $thedb.sql

Ubuntu, apache and using hostnames instead of directories for sites.

OS: Ubunutu 12.x
Web server: apache 2.x

So here is what I was trying to accomplish. I have a server with many sites in their own directories. I had one that I wanted to just use a hostname to access it. Now, I have done this many times in CentOS/Redhat, but never in Ubuntu, and it adds a little twist to the process. First the name needed to be added to the DNS. I created a CNAME, since I already had a name in for the server.

Then:

vi /etc/apache2/apache2.conf

NameVirtualHost *:80
<IfModule mod_ssl.c>
 NameVirtualHost *:443
</IfModule>

cd /etc/apache2/sites-available
</blockquote>

Created a file with a descriptive name of my site:

vi some.hostname.com

Added the following as appropriate for my site:

<VirtualHost *:80>
 ServerName some.hostname.com
 ServerAlias some
 DocumentRoot /var/www/some
</VirtualHost>

There are many other options you can add here, but this is where I started.

cd /etc/apache2/site-enabled
ln -s ../sites-avaiable/some.hostname.com
service apache2 restart

Return top

INFORMATION