Solved

Trouble using connection string to authenticate on SQL Server

Posted on 2011-02-13
5
390 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]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

743 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

17 Experts available now in Live!

Get 1:1 Help Now