-1

I have a DataBase in SQLSever. Into the webConfig file of my MVC project, when i configure the connectionString by giving the user and the password, it's correct:

<connectionStrings> <add name="jcConn" connectionString="Data Source=LAPTOP\MSSQLSERVERAXVAL;Initial Catalog=bd_school;Persist Security Info=True;User ID=sa;Password=namin"/> </connectionStrings>

But I dont want to specify the user and the password. So by trying to do this, it doesn't work:

<add name="jcConn" connectionString="Data Source=LAPTOP\MSSQLSERVERAXVAL;Initial Catalog=bd_school;Integrated Security=True;" providerName="System.Data.SqlClient" />

How can i do that ?

Thank you.

1
  • 2
    Read How to Ask and elaborate on "doesn't work". Commented Jan 23, 2018 at 9:31

3 Answers 3

1

First: Does the user you're logged in as have access to the database you're trying to connect to? If you're running in IIS express then that's the user you're logged into the machine with and if you're hosting in IIS then the user the application pool is running as (assuming you're not impersonating).

Secondly: Integrated Security=true;

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

Comments

0

If you do not want to put your SQL User Id and Password in connection string then you must use Windows Authentication to login in SQL. And use your Database in Windows user in SQL. use this Integrated Security=true;

2 Comments

Okey thnak you guys. But, if i use Windows authentication (by configuring webconfig) as you mentionned, can i create a user table in my database and create user on the database (with attributes[username, password]) ? It will allow me to control user when they connect on the web app mvc. Is it correct like i said ?
Yes you can BUT your data base and web hosting (deployment) should be on same server.
0

If you use SQL login, then you need to specify the username and password in your connection string. If you don't want that, you need to use Windows Authentication. Check this answer in that case.

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.