SMO Connection String conversion

Hi,

I am using SMO in my application to retrieve data from SQL Server in order to display it in the UI (such as DB list, tables list, etc.). Eventually the user has a connection definition screen, in which he inserts his data.

The thing is that in the background my application needs to use this data to connect via OLE DB. Is there a way to convert the connection string generated by SMO to an OLE DB connection string

Thanks.



Answer this question

SMO Connection String conversion

  • Ola Sprauten

    Hi, I guess not, but why do you want to use OLEDBConnection if you can have the SQLConnection The SQLConnection is optimized for SQL Server access, you don’t need the oledbconnection string unless you are dealing with a non compatible versions of SQL Server for the sqlconnection string, which is everything underneath the version of SQL Server 7.0. (Even SMO is only compatible for versions higher than 7.0)

    HTH, jens Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---

  • DPOMT

    Hi,

    if you use the

    Microsoft.SqlServer.Management.Common.ServerConnection to create a server connection, you can use the constructor with the SQLConnection class and its appropiate connectionstring to use that in your OLEDB connection.

    HTH, Jens Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---


  • Jinnyminto

    I need it the other way round.

    I have an SMO server object, created with the common ServerConnection object. The ServerConnection object is created directly from user input on a screen - server and database name, user/password, etc.

    after I use this data and the SMO server to test the connection and bring tables list (for other UI screens), I need to get an OLE DB connection string, to be used in my application backend.

    Is there a way to get from the ServerConnection the matching OLE DB connection string


  • Tillmann

    Hi,

    sorry, AFAIK the conversion from sqlconnection to oleddconnection is not implemented by default, although they share a common interface, the IDBConnection. Perhaps you can build your own helper class which created a OLEDBConnection of the sqlconnection instance on its own.

    HTH, Jens Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---

  • Kent McCroskey

    Hi,

    I didn't quite understand how do I get the SQLConnection and how to use it.

    Can you give me a code sample or a reference to one

    Thanks.


  • falconair

    I am using this data to create an SSIS package.

    in the SSIS package I need OLE DB connection manager (the components I am using require OLE DB connection).


  • DR_CHAOS

    You could either do something like this:

    Using the sqlconnection as is to use it further in any OLEDB tasks:

    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("Data Source=.;Initial Catalog=master;Trusted_Connection=true");
    Server s = new Server(new Microsoft.SqlServer.Management.Common.ServerConnection(conn));


    Or this will get you the connection string directly from the base class:

    Server s = new Server(".");
    // s.ConnectionContext.ToString(); Will get you the connection string

    HTH, Jens Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---


  • SMO Connection String conversion