0

I am wondering how I can add DATA LINK form to my WIN application. You know those forms where Users can choose on witch SQL server they going to connect and what type of security they going to use and on wht database.

Something like on this picture alt text http://img186.imageshack.us/img186/7259/datalink.png

3 Answers 3

2

You can do it through some COM Introp...but then you have to pull in a bunch of Interop assemblies into your project which can be a drag. This code will show the dialog using reflection instead.

public static string ShowDialog( IWin32Window owner, 
                                 string connectionString )
{
    Type dlType = Type.GetTypeFromProgID( "DataLinks", true );
    Type acType = Type.GetTypeFromProgID( "ADODB.Connection", true );

    object form = Activator.CreateInstance( dlType );
    object connection = Activator.CreateInstance( acType ); 

    acType.InvokeMember( 
        "ConnectionString", 
        BindingFlags.Public | BindingFlags.SetProperty, 
        null, 
        connection, 
        new object[]{ connectionString } 
        );  
    object result = 
    dlType.InvokeMember( 
        "PromptEdit", 
        BindingFlags.Public | BindingFlags.InvokeMethod, 
        null, 
        form, 
        new object[]{ connection } 
        );          
    if( result != null && (bool)result )
        return acType.InvokeMember( 
                    "ConnectionString", 
                    BindingFlags.Public | BindingFlags.GetProperty, 
                    null, 
                    connection, 
                    new object[]{} ) as string;

    return null;
}

This basically translates to the following VB Script

form = GetObject( "DataLinks" )
connection = GetOBject( "ADODB.Connection" )
connection.ConnectionString = "existing connection"
form.PromptEdit( connection )
Return connection.ConnectionString
Sign up to request clarification or add additional context in comments.

4 Comments

I am again stacked on this issue, Now I try to send connection sting from app.config file to fill up Initial parameters but I alway get exeption on object result=dlType.InvokeMember. Any advice Thanx in advice
Might actually help to open a new question on SO so the entire problem/resolution can be documented for others.
Thanx on Your attention Ill try yet for while If I couldn't figure it Then I am going to open new SO, But I am kind shamed asking over and over people to do code for me. Best regards
No shame...we all have to learn somewhere. Alot of this stuff is just down right bizzare and you only learn by banging your head on the wall for days at a time.
1

More on that here.

Comments

1

I think that the best choice is to use the code provided from Microsoft here: http://code.msdn.microsoft.com/Connection.

It is the connection dialog used inside Visual Studio.

However, it only works with registered ADO.NET providers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.