2010-06-11 4 views
3

J'essaie de supprimer une entrée ODBC lors de la désinstallation. Quelle est la meilleure façon de procéder? J'ai un projet standard d'installation de VS.C#: action personnalisée à désinstaller

+0

un coup d'oeil http://stackoverflow.com/questions/334939/how-do-i-create-an-odbc-dsn-entry-using-c – volody

Répondre

2

Un plus

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!!"); 
     } 
    } 
} 
} 
+0

Lorsque cela est Classe d'installateur? Je ne vois aucun fichier * .cs dans mon projet d'installation. – sbenderli

+0

Vérifiez http://devcity.net/Articles/339/1/article.aspx – volody

+0

Cela semble fonctionner, merci! – sbenderli

Questions connexes