Click here to Skip to main content
Licence 
First Posted 30 Mar 2004
Views 34,353
Bookmarked 13 times

MyByteFX.DataHelper

By | 30 Mar 2004 | Article
A simple Data Link Property Dialog that can create connection strings used in ByteFX.MySqlClient provider.

Sample Image - MyByteFXImage.gif

Introduction

I'd like to introduce the MyByteFX.DataHelper which works together with the ByteFX.Net provider to create a connection string much like Microsoft's "Data Link Properties Dialog" does. If you have a need to programmatically fetch a connection string, or to display a dialog from your Windows application that allows you to create or change a connection string, this will help you get the job done. This application is intended to be used with the ByteFX.NET provider and MySQL database server.

Note: This does not create a connection string to work with the ODBC driver for MySQL.

Background

In order to fully use this project, you will need to download the ByteFX.NET provider from SourceForge and have MySQL Server installed and setup. This document doesn't cover the installation of MySQL or ByteFx.NET. You will need to refer to their respective documents.

Using the Dialog

The dialog for the most part should be familiar to you and just requires you to enter in the correct values. But if not, the "Data source" refers to the MySQL server name, i.e. localhost or whatever. The user name and password are any valid user ID and password you have setup in MySQL server. If you have entered valid information, you can then click on the database drop down and see a list of databases to chose from. If not, a message box will be displayed telling you to check your user name, password, etc.

Next is the compression option that you have with the ByteFX.NET provider. It's a nice feature and speeds up your time dramatically. Checking this box will add a "compress=true" to the end of the connection string.

Using the code

The DataHelper is comprised of a MyByteFX.DataHelper class and a MyByteFxDialog form. The class is the entry point and is also controls the dialog. The form is used to create or change your connection properties. You can not use the dialog form directly. You will have to create the class first and then call the .ShowDialog(). If you didn't already know, you will need to set a reference to the MyByteFX.DataHelper in your project.

Properties

  • DataSource - Gets/Sets the data source name. The default is {localhost}.
  • Database - Gets/Sets the database name.
  • Password - Gets/Sets the password. Password is encrypted when saved to the registry.
  • RootKeyName - Gets/Sets the root key name used to save your connection properties.
  • ChildKeyName - Gets/Sets the child key name used to save your connection properties.
  • StreamCompression - Gets/Sets, turns compression on or off using named pipes.
  • Table - Future use. Not implemented.
  • UserID - Gets/Sets the user ID used to connect to your MySQL server.

Methods

  • GetConnection() - Returns a prepared connection string.
  • GetDatabaseList() - Returns a string array containing all databases.
  • GetNetConnectionObject() - Returns a closed MySqlConnection object ready to be used.
  • GetTableList() - Returns a string array containing all tables.
  • SetConnection() - Future use. Not implemented.
  • ShowDialog() - Causes the dialog to load current connection values and display the form.

The RootKeyName and ChildKeyName properties, are used to keep your settings apart from other settings you might have. All property values are stored in your local registry using the root and child names. I set the root key to my company name and the child to the application name. You need to set the two key properties before you call any other property or method.

Example:

MyByteFX.DataHelper.DataSettings mDataSettings = 
                      new MyByteFX.DataHelper.DataSettings();
mDataSettings.RootKeyName = "Stuffy Nose Software";
mDataSettings.ChildKeyName = "MyVideoLibrary";
mDataSettings.ShowDialog();

In the example above, you see we have set the two key names first, so when ShowDialog() is called, it retrieves the correct values from the registry. If you didn't set any values for the key names, the default values would have been used. This would have resulted in displaying no values in the dialog. You will also notice we have the ShowDialog() method we have called. The ShowDialog also allows for you to call it passing in a dialog title, in case you want to customize the title of the dialog.

mDataSettings.ShowDialog( "Stuffy Nose Software, Inc" );

Once the dialog is displayed, you can enter in your information and click on the "Test Connection" button. Values are saved two ways. When you click on the "Test Connection" button or click on the "Ok" button.

Now, let's take a look at how we could use this in various ways in our code.

MyByteFX.DataHelper.DataSettings mDataSettings = 
                        new MyByteFX.DataHelper.DataSettings();
mDataSettings.RootKeyName = "Stuffy Nose Software";
mDataSettings.ChildKeyName = "MyVideoLibrary";

//Fetch the whole connection string.
string mMyCon = mDataSettings.GetConnection();

//Fetch just the database name.
string mMyDatabase = mDataSettings.Database;

//Change the database name on the fly.
//Changes are automaticly saved to the registry.
mDataSettings.Database = "MyNewDatabase";

//If you prefer to fetch a prepared MySqlConnection Object
MySqlConnection mMySqlCon = mDataSettings.GetNetConnectionObject();

//You can also retreive a list of all the databases
string[] mMyDatabaseList = mDataSettings.GetDatabaseList();

//Or get a list of all the tables in a database.
//You must supply a valid database name. 
string[] mMyTableList = mDataSettings.GetTableList( "MyDatabase" );

Points of Interest

That is all there is to it. I did mention this early on but I'll do it again, the password is encrypted when it is saved in the registry using System.Security.Crypto routines. This will keep prying eyes from knowing your secrets if you want to use it in any commercial applications.

History

3/30/2004 - Release 1.0

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

CodeSanta

Web Developer

United States United States

Member

I have been developing application for small to medium sized companies for over 15 years with a strong background in Administration. I originaly started my programing days with a handy Radio Shack TRS-80 writing assembler code. As you can see, I enjoy using more advanced programming languages as well as exploring new ones.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionI hope all is well? PinmemberCodeSanta10:42 9 Jul '04  
AnswerRe: I hope all is well? PinmemberThe underdog7:53 16 Nov '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 31 Mar 2004
Article Copyright 2004 by CodeSanta
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid