1

I got the task:

user on login page types login/password, and your application should try to connect to SQL Server using these parameters

And I don't know how to do this on server-side... I was googling it for an hour with no success.

BTW, I'm using ASP.NET MVC

3
  • What specifically do you need to do with SQL Server? Run a query to return data? Insert a record? Do you know the name of the database, table(s), column(s)? Commented Apr 17, 2014 at 11:49
  • @roryap I need to get several values from the table "Calls". How this is connected to my question? I just want to know how can I connect to SQL Server from server-side code using login/password, that's all Commented Apr 17, 2014 at 11:54
  • Does your database actually provide direct logins for users who come to the web page? In other words, if a user comes to your page who has a user account "bob123" and a password "@#4323", does that map directly to a user account associated with your database? Or is it that you connect to your database with an application account and password and your web user accounts are stored as records in the database? I'm not a web developer, but the latter seems like it would be better. Commented Apr 17, 2014 at 12:01

1 Answer 1

2

For an application, where you have access to usernames and password and you wish to connect to SQL Server. Create a connection like

SqlConnection myConnection = new SqlConnection("user id=username;" + 
                                   "password=password;server=serverurl;" + 
                                   "Trusted_Connection=yes;" + 
                                   "database=database; " + 
                                   "connection timeout=30");

then you can use this connection to query the database

See sample code here

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.