Title: RE: [MSVC] Setup Connection String

*** Before acting on this e-mail or opening any attachment you are advised to read the disclaimer at the end of this e-mail ***

Hi
 
> Platform: VC++ .NET, SQL Server 2000, win2k
>
> I'm developing an  application to connect to some database
> and depending
> of user choice connect to the server
> using either windows authentication or SQL Server authentication.
>
> How to do that using connection strings??

Well (even thought you're a dirty rotten cross-poster), this is what we do
in our code:


void Connect ()const
{
    std::stringstream str;

    str << "Provider= " << m_provider << ";"
        << "Data Source=" << m_server << ";"
        << "OLE DB Services = -2;"                             
        << "Persist Security Info=True;";
                               
        if( m_catalog.empty() == false )
        {
            str << "Initial Catalog=" << m_catalog << ";";
        }

        // NT Authentication
        if ( m_user.empty() && m_password.empty() )
        {
            str << "Integrated Security=SSPI;";
        }
                       
        m_pAdoConnection->Open( _bstr_t( str.str().c_str() ),
                                _bstr_t( m_user.c_str() ),
                                _bstr_t( m_password.c_str() ),
                                Ado::adModeUnknown );          
}
 
Connect is a member function of our Connection class. m_user and m_password
are data members and are initialised in the class constructor.

I think it's clear from the code, but if either m_user or m_password ( or
both )are populated then SQL server authentication is used, otherwise NT
Authentication is used.

HTH

Regards
Paul


Paul Grenyer
Software Development Engineer
http://www.paulgrenyer.co.uk
--LongSig

communisis chorleys ltd
Computer Bureau
Manston Lane
Crossgates
Leeds
LS15 8AH

Telephone +44 (0)113 225 5306
Fax       +44 (0)113 225 5914
Email     [EMAIL PROTECTED]


**********************************************************************
Please note: This e-mail and its attachments contain only the opinions of the sender and do not necessarily reflect the policy(s) of the communisis group in general.

Employees of the communisis group are required not to make any defamatory statements and not to infringe or authorise any infringement of copyright or any other legal right by e-mail. Any such communication is therefore outside the scope of employment of the individual concerned. The communisis group will not accept any liability in respect of such a communication.

Confidentiality: This e-mail and any attachments, together with their contents, are confidential unless otherwise explicitly stated in writing by the sender of this e-mail and are for the intended recipient only. If they have come to you in error you must not take any action in respect of them, which includes but is not limited to reproducing, sending or storing them, other than to notifying the sender immediately of the mistake, and deleting the e-mail, any attachments and any reproductions made by replying to it.

Viruses: This e-mail and any attachments have been scanned for viruses but we cannot guarantee that they are virus free. The recipient should check this e-mail and any attachments for viruses. The communisis group accepts no responsibility for any damage caused by any virus transmitted by this e-mail or any of its attachments. In the event of any unauthorised copying or forwarding, the recipient will be required to indemnify the communisis group against any claim for loss or damage caused by any viruses or otherwise.

**********************************************************************


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

Reply via email to