Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trouble using connection string to authenticate on SQL Server

Posted on 2011-02-13
5
Medium Priority
?
404 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 143

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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

916 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