 |
|
 |
I have problem with the wait cursor. It appears when I call PromptEdit method on MSDASC.DataLinks object. I can't disable it.
I would be very greatfull, if somebody tells me what I doing wrong or how could I fix it.
Best regard, Primoz
My code: ------ ///this funcion calls, when I click on Browse button into parentControl. public static bool BrowseConnectionString(Control parentControl, ref string connectionString, ref string dataSource)
MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass(); ADODB.ConnectionClass connection = new ADODB.ConnectionClass(); if (parentControl != null) dataLinks.hWnd = parentControl.Handle.ToInt32();
if (string.IsNullOrEmpty(connectionString)) connection.ConnectionString = "Provider=SQLOLEDB.1;"; else connection.ConnectionString = connectionString; object objconnection = connection; if ((bool)dataLinks.PromptEdit(ref objconnection)) { ... } -----
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
I just found your code now after building a similar class last year. I was doing some Googling to clear up some issues and came across your article, and I thought I'd share an experience with you.
When editing ADO.NET SqlClient connection strings, that don;t include a "Provider=xxx;" part, on opening a connection the dialogue selects the default ODBC provider, where one is used to seeing the SQL Server Provider. I worked around this issue by adding a flag to my class, IsSqlServerProvider, that when set, automatically adds a Provider=SQLOLEDB.1;" to 'incoming' connection strings, so that the editor selects the correct provider for editing, and then removes this from 'outgoing' strings so that the SqlClient provider doesn't complain.
However, I had one problem I had to solve with a kludge: sometimes the editor added "Provider=SQLOLEDB;", without the ".1", so my stripping code missed it. I cannot find why it sometimes adds the ".1" and sometimes not, on the same server and same database, so for now I check for both in some rather smelly code.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
There's no need for ADO interop assembly. We can use the same method to get the connection string:
string connstr = (string)str.GetType().InvokeMember("ConnectionString", BindingFlags.GetProperty, null, str, new object[0]);
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sorry, I didn't read the article carefully enough  We can use reflection and avoid interop assemblies:
Type type = Type.GetTypeFromProgID("DataLinks"); object links = Activator.CreateInstance(type); object str = type.InvokeMember("PromptNew", BindingFlags.InvokeMethod, null, links, null); object s = str.GetType().InvokeMember("ConnectionString", BindingFlags.GetProperty, null, str, new object[0]);
There's user interaction anyway - reflection won't add significant slowdown here.
|
| Sign In·View Thread·PermaLink | 4.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
What am I missing? It is my understanding that PromptEdit takes an object reference to and ADODB Connection, not an object reference to a string?
The downloaded code fails with: "Connection object is not valid. No such interface supported." because of this.
It would be nice if it worked, using the ADODB.Connection the end user must specify the "Allow saving password" to get the connection.ConnectionString property to return the password. If a string would work like this the user wouldn't have to check the box?
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Bummer, unless the user checks the "Allow saving password" which sets Persist Security Info=True the connection string will no longer contain the password entered.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Here is a partial solution to the password issue. With PromptEdit (because it takes a reference to an ADODB.Connection instance) you can setup the Connection object that you pass to PromptEdit so that you can get the password. The Connection class has a Properties member that is a collection of key/value pairs (although the values can be, and often are, null). Many of the properties included in the collection are familiar ("Initial Catalog", "Data Source", "Password", etc.). And one of those properties is "Persist Security Info". You can get and modify this property with the folloing bit of code:
ADODB.Connection connection = new ADODB.Connection(); ADODB.Property persistProperty = connection.Properties["Persist Security Info"]; persistProperty.Value = true;
This causes some non-intuitive behavior: 1) The "Provider" tab will not appear in the dialog box. 2) The ConnectionString property of the Connection instance will still not include the password (unless the user checks the "Allow saving password" check box). 3) (This is the important bit.) The "Password" property will contain the password that the user enters, regardless of what the user does with the "Allow saving password" check box. 4) Coming out, the "Persist Security Info" will refelect the state of the "Allow saving password" check box. 5) Setting the "Persist Security Info" does not set the default state of the "Allow saving password" check box, but setting other properties (such as "Initial Catalog") does set default values in the dialog box.
I have not been able to find a away around the "Provider" tab disappearing. Since I am only interested in SQL databases (for the moment), I just set the "Provider" property on the Connection object before calling PromptEdit as follows:
connection.Provider = "SQLOLEDB.1";
For some reason any access of the "Properties" method of the Connection instance that you pass to PromptEdit prior to calling PromptEdit will cause the "Provider" tab to disappear. This is true even if you just get the count for the properties collection.
In any case, the password can be retrieved with this line of code:
string password = connection.Properties["Password"].Value.ToString();
Remember that the ConnectionString property may or may not include the password, so you will likely not be able to just use the connection string without some processing.
-- modified at 5:06 Tuesday 4th July, 2006
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
I want to be able to select a provider on the provider tab. Then go to the connection tab. In connection tab I want to check the "allow saving password" checkbox and hide it as well programmatically. Is there any way of doing it?
Or in other words all i want is to be access the password from the connection tab regardless of whether the "Allow saving password" checkbox is selected or not.
Any help greatly appreciated.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Of course, there is nothing slow about calling PromptXXXX(). However, it would be very slow to rewrite OleDb32.dll.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I am sure he probably did not even try the code ... he just saw the COM interop and immediately thought slow which is not always true.... This tip is a great way to provide an easy to develop way to create an UI for generating connection strings.
I have not profiled what goes on in VS.NET when in server explorer under Data Connections what code is being run when one chooses New Data Connection.. My guess is code similar to this.
Marty
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Really matters the Time ???
I am developing an Application to configure the Production Servers of our Customer and I am using the UDL to avoid the customer to edit manually the Enterprise Library Data Access Files Config Files
Who mind's a seconds???
Very Good Article, you solve my problem with the PromptEdit()
ps: Maybe it could be a good idea to give the Exact Name of the COM component
because also this can be added in the COM tab, the component is "Microsoft OLE DB Service 1.0 Component Type Library"
( a pity this dll don't have a strong Name, I cannot sign this part of the project....
Ricardo Casquete
|
| Sign In·View Thread·PermaLink | 1.67/5 (2 votes) |
|
|
|
 |