I am trying to remove an ODBC entry during uninstall. What is the best way to do this? I have a standard VS Setup project.
+1
A:
One more
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Runtime.InteropServices;
namespace MyInstallerClassDll
{
[RunInstaller(true)]
public partial class MyInstallerClass : Installer
{
const int ODBC_REMOVE_DSN = 3;
public MyInstallerClass()
{
InitializeComponent();
}
public override void Uninstall(System.Collections.IDictionary savedState)
{
RemoveSystemDSN();
base.Uninstall(savedState);
}
[DllImport("ODBCCP32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int SQLConfigDataSource(int hwndParent, int fRequest, string lpszDriver, string lpszAttributes);
private void RemoveSystemDSN()
{
string vAttributes = "DSN=DSN Name" + Strings.Chr(0);
vAttributes += "Description=DSN Description" + Strings.Chr(0);
vAttributes += "Trusted_Connection=Yes" + Strings.Chr(0);
vAttributes += "Server=SQLINSTANCE" + Strings.Chr(0);
vAttributes += "Database=databasename" + Strings.Chr(0);
if (SQLConfigDataSource(0, ODBC_REMOVE_DSN, "SQL Server", vAttributes) == 0)
{
MessageBox.Show("Failed to remove ODBC data source!!");
}
}
}
}
volody
2010-06-11 13:39:39
Where is this Installer class? I do not see any *.cs files in my Setup project.
sbenderli
2010-06-11 13:41:32
Check http://devcity.net/Articles/339/1/article.aspx
volody
2010-06-11 13:58:12
This seems like it will work, thank you!
sbenderli
2010-06-11 15:31:55