SD Card unexpectedly removed [Android]

Today while I was trying to take a picture of my son wearing his costume with my new HTC G2, got the error message “SD Card unexpectedly removed”. I asked myself: how is that possible if the card is inside and even behind the battery.

Before I continued trying, decided to turn off the phone, extract the card, clean the contacts and try again. Everything went well until 20 minutes later; I got the same error again.

I performed the process again, this time thoroughly cleaning the pins on both the G2 and the SD card. I was able to record my son’s parade and even upload to YouTube, but yet again the error message came up once more.

Searched on Google, called a friend and even called T-Mobile to see if there was any known issue. Didn’t get too much help so I went ahead and performed a CheckDisk with repairs (while plugged in to the USB port of my PC). I thought it was fixed after it, but minutes later, again the issue reoccurred.

I decided to use a MicroSD adapter, plugged into my computer, tried to save whatever I could from the latest pictures and videos I took (luckily it was just 2 weeks worth) and formatted it like 3 times. I did not choose a quick format option just to ensure that all blocks get touched.

All good? No. Seems that the card is bad. Called T-Mobile, called, HTC, there are no replacement cards for the HTC G2 yet. What? It is a universal card! But no, HTC says that I need to call when they get stock parts for the HTC G2.

I guess I am out of luck on this one. I will need to buy another card.

Luckily, all the previous contents were safely backed up to the cloud.

Editing a Profile in MSDN Social Forums returns “Sorry, we were unable to service your request. Please try again later.” [MSDN]

I was unable to post a question, reply or even edit my profile for over a month. Microsoft support took that long to send me this workaround.

After following this process, I was able to gain access to the forums.

This is an exact copy of what Microsoft Support sent me:

1. Open http://msdn.microsoft.com/en-us/library/ff361664.aspx

2. Sign In (with the account which is giving problem)

3. Select preferences from on masthead

4. Select classic version, save, takes back to previous page

5. Scroll down to community content section

6. Your display name shows up on below community content section, looks like below

7. Click your display name, takes to edit page. Edit display name and save, looks like below

8. Re-login from Forums application (if still seeing the issue, wait for couple of hours and retry again).

Summarizing Performance issues and workarounds after migrating from 2005 to 2008 R2 [SQL Server]

Based on our experience, having Hyper Threading (HT) enabled on one particular node let to I/O operations take a very long time. This was on a Windows 2008 R2 Cluster running SQL Server 2008 R2. An interesting fact was that it was neither reflected in the wait stats nor in the pssdiag we ran for Microsoft support.

The way we noticed low I/O was just by watching the OS counters for physical disk. I wrote about it here and here.

After fixing the issue by disabling HT, we started experiencing a very high CPU utilization due to a excessive amount of logical reads (20 million per query). This was due to a really bad plan. Our processes were performing anti-semi joins with tables that were partitioned and  the code that was performing extremely bad in 2008 R2 while doing just fine in 2005. I wrote about it here.

We pinpointed it out by running Adam Machanic’s sp_whoisactive while under high load  (which can be downloaded from here).

We also ran server side traces to find out the most expensive operations by sorting the highest I/O and CPU utilization metrics.

With the steps above we were able to tune the offending processes and go from 85% sustained CPU utilization to almost nil.

High CPU Utilization

Most Developers Have No Business In The Database World

I have been around superb developers that understand the concept of approaching efficient code that needs to be ran on the database, and will seek help from database developers/DBAs to ensure that is the case. Unfortunately, most do not really understand the need and approach a solution to certain requirement with one thing in mind: effectiveness.

Yes, If business folks request a page that will show up all kinds of fancy data and drop downs, they will do it. It does not matter if the code behind the scenes goes through an expensive loop to render each record one-by-one.

The database is the most difficult and expensive Tier to scale, and code needs to be written in a way so it does the less amount of reads to get the answer to certain request. Developers need to understand that effectiveness needs to be tied with efficiency whenever they are coding.

If they do not understand/do not know how to make efficient code then seek help from a Database Developer/DBA. For example, why code a process that updates one row at a time instead of performing a bulk operation that updates all at once? Didn’t they know that a nested loop can be the worst route instead of hash or merge join to perform an update? Reducing trips to the I/O subsystem really makes a difference.

Now, there are other type of developers that think they know the answer for improving performance to any database without even looking at their code. I have experienced situations where I was told “we need more indexes” or “the database is timing out” when the issue was another heavy process taking long I/O requests and the developer had an uncommitted transaction respectively.

If developers have a problem, work as a team. Ask for help to someone that really knows their business so they can perform a health check. Imagine if a DBA goes and tells a developer how to write their application tier code.

I have not seen any DBA that has morphed onto being a developer. Most cases are the opposite, where developers become DBAs. I have experienced it myself as a former developer (yeah the procedural days) and DBA. If DBAs become developers this will be a perfect world, as the efficiency techniques will be considered while coding application and web tier code.

My final thoughts are, DBA’s own the database; it does not matter what the developer says. If a developer has an idea, then express it as it; do not demand what needs to be done to a database as they are most likely wrong.

And no, creating a single index on each field will not make the database faster. Let the DBA collect statistical facts and go from there.

Kerberos Double Hop and Delegation between different Active Directory Accounts [SQL Server]

In the past, when I had bare knowledge of Active Directory, I dealt with double hop queries using SQL Server Authentication.

What is the problem with SQL Authentication? Maintenance. The DBA team can literally spend hours maintaining usernames/passwords, linked servers, and of course giving appropriate grants/roles to a new user added to several database instances. There are also security concerns which is outside the scope of this post.

So what is a double hop query? It is a query ran from Machine A that requests data from machine B that at the same time requests data from Machine C.

For example:

If I execute a query on my local machine (A) connecting to Server1 (B) that requests data from Server2 (C):

1
2
3
4
5
-- From my desktop:
SELECT a.*
FROM OPENROWSET('SQLNCLI',
'Server=server2.domain.com\instance;Trusted_Connection=yes;',
'SELECT * from master.sys.objects') AS a;

The solution: Active Directory. A user can be added to the DBA Domain Group, and that group can be granted the sysadmin role on every production database server for example. Once that is defined, we can add/remove members of the group without even touching the database instances.

Now, there is a consensus of having each database instance use its own Active Directory Account as SQL Server Service user. Some shops have 1 account, others a few. It depends on the policy adopted.

Our challenge: Allow double hop queries between 2 database instances running different Active Directory Accounts.

The solution was similar to what we have done with 1 single account.

This is how me made it work for 1 account:

Prerequisites:

  1. You need domain admin or access to Active Directory under the domain managed
  2. The person in charge of making the change has access to the domain controller or has Remote Server Administration Tools installed locally.

Steps:

  • Via Command Prompt, execute the SETSPN command for the server, port and domain account assigned for the SQL Server Instance.
1
setspn -a MSSQLSvc/server1.domain.com:1433 DOMAIN\srvc_sqlaccount
  • For clustered solutions, run it with and without port number. It does not matter if it is a named instance.
1
2
setspn -a MSSQLSvc/serverclust1.domain.com DOMAIN\srvc_sqlaccount
setspn -a MSSQLSvc/serverclust1.domain.com:1433 DOMAIN\srvc_sqlaccount
  • This needs to be repeated for all the SQL Server Instances that you need to trust delegation
  • Open Active Directory Users and Computers, search for the domain account just used (DOMAIN\srvc_sqlaccount) in the example, double click and open the properties window.
  • Enable “Trust this user for delegation to specified services only”, “Use Kerberos Only”, Add, User and Computers, type in the account used (e.g. srvc_sqlaccount), select the machine(s) you want to trust delegation, OK, OK.

This is how we made it work with 2 accounts:

You need to follow the same exact process, but when enabling Kerberos delegation, you need to open the properties of the first domain account and add Kerberos Delegation to the second domain account.

Assuming non-clustered instances:

Steps:

  • For the first account and the first instance. Via Command Prompt, execute the SETSPN command for the server, port and domain account assigned for the SQL Server Instance.
1
setspn -a MSSQLSvc/server1.domain.com:1433 DOMAIN\srvc_sqlaccount_1
  • For the second account and the second instance. Via Command Prompt, execute the SETSPN command for the server, port and domain account assigned for the SQL Server Instance.
1
setspn -a MSSQLSvc/server2.domain.com:1433 DOMAIN\srvc_sqlaccount_2
  • Open Active Directory Users and Computers, search for the first domain account (DOMAIN\srvc_sqlaccount_1) in the example, double click and open the properties window.
  • Enable “Trust this user for delegation to specified services only”, “Use Kerberos Only”, Add, User and Computers, type in the first account used (e.g. srvc_sqlaccount_1)
  • Select the machine you want to trust delegation (server1.domain.com in the example), OK, OK.
  • Click Add again, User and Computers, type in the second account used (e.g. srvc_sqlaccount_2)
  • Select the machine you want to trust delegation (server2.domain.com in the example), OK, OK.
  • Wait enough time for the Domain Controllers to propagate the changes (15 minutes should be fine)

Verify Logins are Connecting Via Kerberos:

Run the following query, paying special attention to the auth_scheme column. If Kerberos authentication was successful, you should see the auth_scheme reflect Kerberos instead of NTLM:

1
2
3
4
5
6
7
8
9
10
11
12
SELECT
s.session_id
, c.connect_time
, s.login_time
, s.login_name
, c.protocol_type
, c.auth_scheme
, s.HOST_NAME
, s.program_name
FROM sys.dm_exec_sessions s
JOIN sys.dm_exec_connections c
ON s.session_id = c.session_id

Now we can have multiple Domain Accounts for multiple SQL Database Instances, each one delegating for double hop.

Hope this helps.