When using a provider string with a local SQL Server user, say "MyName" with a password "MyPassword", a typical string would look like this:

use Win32::OLE; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; $strProvider = 'Provider=sqloledb;Data Source=MyServerName;Initial Cat +alog=MyCatalog;'; $strProvider .= 'User Id=MyName;Password=MyPassword'; $strQuery = "SELECT 1 AS SystemName"; $objConn = CreateObject Win32::OLE "ADODB.Connection"; $objConn->Open($strProvider); $objRS = $objConn->Execute($strQuery); if ($objRS) { while ( !$objRS->EOF ) { my($SystemName) = ( $objRS->Fields('SystemName')->value ); print "SystemName: ", $SystemName, "\n"; $objRS->MoveNext; } } else { print "This doesn't work!!!\n"; }

This code should print a simple "1" as data... and this does indeed work. Now, if we go and add a Domain Name to the User, things don't work, and I can't figure out why... I've tried many different variations with the "/" (I've done double backslash, double forward slash, singles, even quads, but none of them work).

This is what the provider string would look like:

$strProvider = 'Provider=sqloledb;Data Source=MyServerName;Initial Cat +alog=MyCatalog;'; $strProvider .= 'User Id=MYMACHINE\MyName;Password=MyPassword';

This doesn't work, and it's really bugging me... Anyone have any ideas as to how to get a user that has a domain name to connect to a SQL Server?


In reply to How can I add a Domain into the UserName of a Provider String using Win32::OLE by Incognito

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.