Friday, March 25, 2016

“Semicolon Mode”

I think I coined a new term this week.

Several C-like languages (C#, Javascript, Objective-C, etc.) end statements with a semicolon. Other languages (Visual Basic, Python, etc.) don’t.

I had been writing some C# for a while and switched over to work on a Visual Basic project. I found myself putting semicolons at the end of the VB lines and said to myself: “Hey, I’m still in ‘Semicolon Mode’”. Smile

Saturday, March 19, 2016

Parsing .NET Connection Strings

Have you ever wanted to get a piece of a connection string? Like say the database? There’s no need to grab IndexOf and Substring and try it parse it yourself. .Net already has the ability to parse connection string using the StringConnectionBuilder:
using System.Data.SqlClient;
var conString = "Server=myServerAddress;Database=Customers;User Id=tim;Password=lassie;";
var s = new SqlConnectionStringBuilder(conString); var datasource = s.DataSource;   // "myServerAddress" var database = s.InitialCatalog; // "Customers" var username = s.UserID;         // "tim" var password = s.Password;       // "lassie"

Friday, March 4, 2016

SSMS Tips

I’ve been working a lot with Sql Server Management Studio (SSMS) lately and thought I’d share some tips I’ve ran across to make it easier to use.

1) Change the number in Select & Edit.

When you right-click on a table in SSMS two of the options you are given are “Select Top 1000 Rows” and “Edit Top 200 Rows”. You can change these numbers. To do so, select Tools –> Options in the menu. In the Options dialog select “SQL Server Object Explorer”. Under Table and View Options you can change the default values.

image

2) Change the connection color

You can change the color at the bottom of the query window based on the database you are connected to. On the connection dialog select “Options >>”. Then select the “Use custom color” dialog and use the “Select” button to pick a color. Now when you’re connected to the database, the bottom of the query editor window will be the color you selected. I like to set my TEST database to green and the PROD database to red.

image

3) Change the Edit Rows Query

When you right click on the table and select “Edit Top 200 Rows” you are given these rows to edit. But wouldn’t it be nice if you could change the WHERE clause to show just the records you want? Well you can. First select “Edit Top 200 Rows”. Then from the menu, select Query Designer –> Pane –> SQL. Here you can edit the SQL that returns the records for editing. Once you’ve edited it, right-click on the query window and select “Execute SQL”. Now you can edit just the rows you selected.