Wednesday, March 11, 2009

Create a MS SQL link to MySQL database

To create a MS SQL link to MySQL database, first be sure to install the MySQL ODBC Connector from here: http://dev.mysql.com/downloads/connector/

Create a new System DNS for the MySQL Database on the ODBC Data Source Administrator from the Control Panel | Administrative Tools

To establish a link to the MySQL database from the Microsoft SQL Server Management Studio, open a query window and run the following SQL statement:

EXEC master.dbo.sp_addlinkedserver
@server = N'MYSQL',
@srvproduct=N'MySQL',
@provider=N'MSDASQL',
@provstr=N'DRIVER={MySQL ODBC 5.1 Driver}; SERVER=localhost; DATABASE=; USER=root; PASSWORD=; OPTION=3'


This script will produce a link to the MySQL database through the ODBC connection.




Wednesday, March 4, 2009

Installing mySql on ubuntu

To install mySql on ubuntu, type the following command on the terminal window
sudo apt-get install mysql-server
To create a new database, type the following mysqladmin command:

mysqladmin create -uroot -p

If you are running PHP you will have to install the php module:
sudo apt-get install php5-mysql

If you want to give Root user logon permissions from any host computer on the network, you will need to update the mysql user table, using the % wildcard. Type the command on the terminal to open the command-line mysql client on the server using the root account.
mysql -uroot -p

to see what the root user host has permissions for, type,
use mysql;
select host, user from user;

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user from user;
+-------------+--------------------------+
| host | user |
+-------------+--------------------------+
| 127.0.0.1 | root |
| localhost| |
| localhost| debian-sys-maint |
| localhost| root |
| ubuntu | |
| ubuntu | root |
+-------------+--------------------------+
6 rows in set (0.00 sec)

to update the ubuntu host to use the wildcard, and then issue the command to reload the privilege tables, type,
mysql> update user set host='%' where user='root' and host='ubuntu';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Now its possible to connect to the server from any other computer on the network, using the root user account. Doing this has some secure issues, beware to set a password for the root user accont.



Thursday, January 29, 2009

.Net Application Single Instance

If you want to ensure that your application only runs one instance at a time, the best method is to use a Mutex.

Mutex: Short for mutual exclusion object. In computer programming, a mutex is a program object that allows multiple program threads to share the same resource, such as file access, but not simultaneously. When a program is started, a mutex is created with a unique name. After this stage, any thread that needs the resource must lock the mutex from other threads while it is using the resource. The mutex is set to unlock when the data is no longer needed or the routine is finished.

On your program.cs unit, do the following:

  
static class Program
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
bool createdMutex = false;
Process currentProcess = Process.GetCurrentProcess();

Mutex mutex = new System.Threading.Mutex(true,
currentProcess.ProcessName + currentProcess.MachineName + " Mutex", out createdMutex);

if (createdMutex)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());

GC.KeepAlive(mutex);
}
else
{
// Application to topmost window
foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName))
{
if (process.Id != currentProcess.Id)
{
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
}
}

Tuesday, January 20, 2009

Exception of type 'System.ComponentModel.Design.ExceptionCollection' was thrown

Sometimes I get the message "Exception of type 'System.ComponentModel.Design.ExceptionCollection' was thrown" When trying to open a Form in designer view.
The real problem of the "ExceptionCollection" being thrown is that when there is a WSOD (White Screen of Darn) indicating a designer load issue, the designer gets unloaded. These get caught by the unload method and get displayed in the dialog box you see.
So, to fix this you should:
* Attach a visual studio debugger to VS. Turn on exception catching when first thrown (in the Debug|Exceptions menu).
* Open the designer with the debugger attached
* Determine what component is throwing the exception.

Sometimes you cannot open the form design view because of a missing resource file or an invalid reference in the design code unit.

Thursday, January 8, 2009

Enable remote connection to SQL Server 2005 Express

How many times did you had the following error on SQL Server 2005 Express, "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connection". Check this post on Linglom’s blog and a step by step solution for the problem.

Another solution is to go to SQL Server Configuration Manager on Microsoft SQL Server 2005 folder at Start menu, under Configuration Tools. Select SQL Server 2005 Services, and change the State and Start Mode of SQL Server Browser item to Running and Automatic.

Hopefully it will solve your problem ;-)

Monday, November 10, 2008

Unable to open Server Explorer in Visual Studio

When server explorer doesn't open when clicking on the menu option View|Server Explorer, the first solution is to run the command /ResetSkipPkgs on the visual studio command prompt. Open a development command line window by clicking on the Start|Programs|Microsoft Visual Studio 2008|Visual Studio Tools|Visual Studio 2008 Command Prompt shortcut.
Type devenv /resetskippkgs in there. What /ResetSkipPkgs does is that it clears all options to skip loading added to VSPackages by users wishing to avoid loading problem VSPackages, and then starts Visual Studio. The presence of a SkipLoading tag disables the loading of a VSPackage; clearing the tag re-enables the loading of the VSPackage.

If this doesn't work, then reinstall the visual studio again.