Solved

Trouble using connection string to authenticate on SQL Server

Posted on 2011-02-13
5
391 Views
Last Modified: 2012-05-11
The following connection string works fine when I'm already logged in to a computer on our intranet:

"Server=sname;User ID=my.name;Database=DatabaseName;Trusted_Connection=true"

But from home, using a VPN connection into the intranet, the connection string fails because I'm obviously not "logged in".

I tried the obvious approach of adding my password:

"Server=sname;User ID=my.name;Database=DatabaseName;Password=secret;Trusted_Connection=true"

But this doesn't work. For future reference, I normally log on to a computer named
"Corp123" with a domain of "corpdomain".

I'm using SQL Server 2008, and Visual Studio 2010 to perform the connection using C#.

If source is my connection string, then the following is the code I use to log in from C#:
               SqlConnection conn = new SqlConnection(source);
                conn.Open();
                SqlCommand cmd = new SqlCommand(@"StoredProcedureName", conn);
              ....


I appreciate any help anyone can give. I believe, most likely, that I have the permission to access the database as long as my connection string contains authentication information. But if it's likely I need special rights, please tell me what specific rights I need to ask for from my database adminsitrator. (My DBA's head pops off in response to vague security requests).
0
Comment
Question by:Ryan94114
  • 2
  • 2
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34884216
it means that indeed, the SQL Server cannot tell your current windows login information.
and using windows authenticaation will only work if the sql server can "tell" your windows login.
otherwise, you will need to use sql logins.
0
 

Author Comment

by:Ryan94114
ID: 34884636
Reading your message, I have no idea (a) whether or not I may be able to log in using a connection string, and (b) what request to my database admin would result in success.

Remember, I do have access to my own username and password, and can supply them in the connection string if this is helpful.

in summary, does your answer mean (a) or (b) below:

                 (a)  I need to supply authentication information _within_ the connection string, in which case the question becomes what changes are needed to the string in order to authenticate?

                  or

                 (b) a username must be added to SQL Server 2008 before any such connection string would work

0
 

Author Comment

by:Ryan94114
ID: 34884648
A tertiary possibility is that VPN's permit logging on to the network, in which case the question would become, how does one log in remotely to a vpn network to satisfy a SQL Server database. on that vpn.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 34885711
you cannot supply windows login information yourself in the connection string.

so, either your local windows machine login information must be added (as windows login) to the sql logins (however, I am not sure if the SQL Server can resolve - and hence trust - the remote login source... )
otherwise, you need indeed a classic sql login created in the sql logins, and THAT login/password shall be passed in the connection string, but you then need to remove the part "trusted_connection ..."
0
 
LVL 11

Expert Comment

by:mattibutt
ID: 34886166
You can try mssql management studio to see whether you can login using your sql username and password another thing you try is the ip address for connection string instead pf server name
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now