Bad Habits: Using AttachDBFileName
Just about every time I look through SQL Server-related questions on Stack Overflow, I see someone describing a problem that they are blaming on their code, but is likely caused by their connection string. The pattern is usually something like:
While sometimes it can be because they are connected to the wrong database, and sometimes it can be because they are looking at the wrong copy of the table (maybe they forgot to specify the schema), and sometimes it can be a simple typo or an unnoticed filter, it is often due to a combination of connection settings. So I always ask to see the connection string before trying to debug code which may seem and actually be perfectly fine; when this is the reason, the connection string will look something like this (emphasis mine):