Click to See Complete Forum and Search --> : Connection String Blues


plnelson
January 25th, 2009, 12:38 PM
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!

hspc
January 25th, 2009, 01:06 PM
Can you post the connection string and the complete error message?

plnelson
January 25th, 2009, 04:08 PM
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.

darwen
January 25th, 2009, 08:53 PM
SQL server is probably using windows security - try this :


Data Source=GEMINI\\SQLEXPRESS;Initial Catalog=HWDB2;Integrated Security=True


Don't have any spaces between the '=' and the connection string.

Darwen.

nabeelisnabeel
January 26th, 2009, 01:20 AM
plnelson!

What happend to your problem ?

plnelson
January 26th, 2009, 07:50 AM
SQL server is probably using windows security - try this :


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!

darwen
January 26th, 2009, 08:42 AM
Another satisfied customer. Ding ! Next please... :D

Darwen.

P.S. I'm glad it was something that simple...

cjard
January 26th, 2009, 09:55 PM
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

hspc
January 27th, 2009, 01:40 PM
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