Connect To SQL… a utility for C# programmers

You are writing a tool for SQL programmers by using C#, SQL Management Objects etc. You need to connect to a SQL Server instance and so you need to code a way to ask for the Server name, user credentials and so on. Why rewrite it each and every time? Simply add boB ‘The Tool Man’ Taylor’s Connect To SQL class, override one method and set your application icon and voila! You have a reusable resource that will allow you to connect to any SQL Server instance along with any SQL Azure Database server instance.

 

Here is an example of the Connect To SQL dialog being used in another project of mine.

 

ConnectToSQL

Let’s examine the solution…

First we must add references to the libraries we will be using to connect to SQL Server instances.

References

 

There are two standard resources included in the ConnectToSQLBase class which you can replace in the constructor to customize the look for your application.

1. A default icon for use by the dialog

ConnectToServer

 

2. A default banner for use by the dialog

ConnectionDialog

 

The key task in order to use ConnectToSQLBase in your project is to override the one virtual function

protected virtual void DoWork(SqlConnection con, SqlConnectionInfo sci)

In this method you have access to the open connection and any Connection Info you might need to perform your tasks.

 

In the next post we will examine the code that performs the authentication and connection features as well as builds the server list when the user selects <Browse for more…> option in the Server Name combo box.

Comments

  • Anonymous
    April 08, 2016
    That sounds interesting! Where can I get your utility?
    • Anonymous
      August 24, 2016
      I will be posting it this month on CodePlex. I will post here once it is available
  • Anonymous
    September 07, 2016
    Sorry for the delay in this series. I will be posting new entries this week and hosting the code on CodePlex as well