So was hacking a new installer and wanted to display the data link properties dialog, for building a connection string.
Here is what I have found out by playing with it.
One has to add the reference to ADODB.DLL (from .NET reference) and Microsoft OLE DB Service Component 1.0 Type Library from the COM tab in your visual studio reference tab.
Here is some sample code, assuming that you have a button and a textbox on the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using ADODB; using Microsoft.Win32; public partial class ConnectionStringStep : Form { private const string MSSQL_PROVIDER = "Provider=SQLOLEDB.1"; private const string ORACLE_PROVIDER = "Provider=MSDAORA.1"; private const string MSSQL = "MSSQL"; public ConnectionStringStep() { InitializeComponent(); } private static string DataBaseType() { //get the data from some previous screen or some kind of storage return MyStorage.GetProperty("DATABASE_TYPE") ?? "MSSQL"; } private void button1_Click(object sender, EventArgs e) { var dataBaseType = DataBaseType(); var adodbConnection = new Connection { ConnectionString = dataBaseType == MSSQL ? MSSQL_PROVIDER : ORACLE_PROVIDER }; object connection = (object) adodbConnection; var dialog = new MSDASC.DataLinks(); dialog.PromptEdit(ref connection); connectionTextBox.Text = adodbConnection.ConnectionString; } } |
Once a user clicks on build, the Data Link Properties Shows up.
Also note: that I am providing some default into the connection, since if you do not provide “Provider=SQLOLEDB.1” then the default is just OLE database not the MSSQL database option.
thanks for this handy tutorial 🙂