CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2008
    Posts
    25

    Connection String Blues

    I'm learning SQL and how to access it from C#.

    This is all on the same machine running XP Pro and .Net 2.0 - I've created a database in SQL Server Express and can manipulate it just fine from the SSMSE console. But when I try to open a connection to it in C# using the SqlConnection.Open() method it say's I'm "Not associated with a trusted SQL Server connection".

    I've tried different things in the User Id and Password parameters in the connection string, including my PC login password and not using them at all (hoping it would take the default).

    When I start up the SSMSE it lists the "User name" as "GEMINI\peter" (GEMINI is my PC) but if I use that in the connection string it just says GEMINI\peter is not associated with a trusted SQL Server connection.

    How do I figure out what it wants? Thanks in advance!

  2. #2
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: Connection String Blues

    Can you post the connection string and the complete error message?
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  3. #3
    Join Date
    Dec 2008
    Posts
    25

    Re: Connection String Blues

    Quote Originally Posted by hspc View Post
    Can you post the connection string and the complete error message?
    The error message varies slightly with the string but if I use my PC login (xxxx is not the real password) in the string -

    "Data Source= GEMINI\\SQLEXPRESS;Initial Catalog=HWDB2;User Id=GEMINI\\peter;Password=xxxx"

    I get

    Exception: Message: Login failed for user 'GEMINI\peter'. The user is not associated with a trusted SQL Server connection.
    Source: .Net SqlClient Data Provider


    if I use no user id and password, hoping it will default to the current user (which is, after all, what SSMSE says it's using) . . .

    "Data Source= GEMINI\\SQLEXPRESS;Initial Catalog=HWDB2;"

    I get

    Exception: Message: Login failed for user ''. The user is not associated with a trusted SQL Server connection.
    Source: .Net SqlClient Data Provider


    Note that GEMINI is the name of the PC.

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Connection String Blues

    SQL server is probably using windows security - try this :

    Code:
    Data Source=GEMINI\\SQLEXPRESS;Initial Catalog=HWDB2;Integrated Security=True
    Don't have any spaces between the '=' and the connection string.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  5. #5
    Join Date
    Apr 2006
    Posts
    220

    Re: Connection String Blues

    plnelson!

    What happend to your problem ?

  6. #6
    Join Date
    Dec 2008
    Posts
    25

    Resolved Re: Connection String Blues

    Quote Originally Posted by darwen View Post
    SQL server is probably using windows security - try this :

    Code:
    Data Source=GEMINI\\SQLEXPRESS;Initial Catalog=HWDB2;Integrated Security=True
    Don't have any spaces between the '=' and the connection string.

    Darwen.

    THANKS!! That worked!

  7. #7
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Connection String Blues

    Another satisfied customer. Ding ! Next please...

    Darwen.

    P.S. I'm glad it was something that simple...
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  8. #8
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Connection String Blues

    Quote Originally Posted by darwen View Post
    P.S. I'm glad it was something that simple...
    Until he tries it across a network whose machines don't share credentials..

    Integrated Headache = True
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  9. #9
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: Connection String Blues

    Quote Originally Posted by cjard View Post
    Until he tries it across a network whose machines don't share credentials..
    Yes, but:

    • Windows authentication is the recommended mode because it is considered more secure
    • Most enterprises now have domains that make credentials normally shared
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured