-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.

Ka Res
  • 311
  • 2
  • 3
  • 17
determine
  • 3
  • 2

3 Answers3

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;

David Perry
  • 28
  • 1
  • 7
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;

  • 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 ? – determine Jan 24 '18 at 16:35
  • Yes you can BUT your data base and web hosting (deployment) should be on same server. – Fazal Qayyum Jan 25 '18 at 06:10
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.