Can't connect to database when database has user and password - sql

I am developing mvc 4 projects and when I use the following connection string it works:
<add name="name"
connectionString="Server=.\sqlexpress;Database=dbname;
Trusted_Connection=true;"
providerName="System.Data.SqlClient"/>
But when I add a username and password to this project, I can't connect to my database. I added the user credentials correctly. I have db_owner permission for this database, and in my database everything is correct. The connection string below does not work:
<add name="DocContext"
connectionString="Server=.\sqlexpress;Database=DocContext;
User ID=pooria;Password=19216801;Trusted_Connection=false;"
providerName="System.Data.SqlClient"/>

Connection String You are using follows format -
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
User ID=myDomain\myUsername;Password=myPassword;
Try using IP Address, Port in Data Source field like -
<connectionStrings>
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=190.190.200.100,1433;
Initial Catalog=MyDatabaseName;
Integrated Security=False;
User ID=MyUserID;Password=MyPassword;
MultipleActiveResultSets=True" />
</connectionStrings>
And the following link may help you
LINK

Related

SQL Server (Linked Server)

My database is from a linked server and I have a problem with my connection string in ASP.NET (web.config) it says that :
Database schema could not be retrieved for this connection. Please make sure the connection settings are correct and that the database is online. Cannot open database "AA" requested by the login. The login failed. Login failed for user 'sa' at DataObjectSupport(423,6)
I try to use this connection string.
<connectionStrings>
<add name="localconnection" connectionString="Data Source=SERVERNAME;Persist Security Info=True;Initial Catalog=database; uid=sa; Password=password; " providerName="System.Data.SqlClient"/>
</connectionStrings>

Unable to login with user that I created in sql database

I'm trying to connect with my DB using a account that I created with db_owner rights. Windows authentication works but not sql server authentication
I can confirm that the role was created as there is a error message login failed for user when using a wrong password. Compared to when correct password.
My local db is created in ASP.net web application by simply adding a local db in App data.
Error message is
user guest does not have permission to run DBCC checkpriamry file.
User has been created using
CREATE LOGIN [SomeUser] WITH PASSWORD = 'topsecret';
CREATE USER [SomeUser] FOR LOGIN [SomeUser];
exec sp_addrolemember 'db_owner', 'SomeUser'
EDIT:
<connectionStrings>
<add name="Shop" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Shop.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
https://imgur.com/a/9aCWVCU
are the links of error message
Your connection string when define login must be like this :
<connectionStrings>
<add name="Shop" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Shop.mdf;Initial Catalog=Shop.mdf;Persist Security Info=True; User ID=SomeUser; Password=topsecret;"
providerName="System.Data.SqlClient" />
</connectionStrings>

Failed login for user

I'm developing a website for sharepoint using asp.net, it is connected to a database. In visual studio server explorer, the database is accessible using a new sql user I created. I granted sysadmin permissions to that user. However, when I deploy the site and run it, it gives me this error 'login failed for user'.
The sql server is configured to allow mixed authentications. I restarted the server, I played with the user permissions but nothing ever changed.
The connection string I got it from server explorer which I'm sure it is correct:
Data Source=servertest;Initial Catalog=qDB;User ID=me2;Password=***********"
What should I do? I've tried every possible solution I found on google and I ended up here.
Try like this by editing your connection string:-
Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;
I too had same scenario this worked for me
<connectionStrings>
<add name="connectionstring" connectionString="Data Source=XYZ\SHAREPOINT;Initial Catalog=DBName;Integrated Security=true;" providerName="System.Data.SqlClient" />
</connectionStrings>
You can Use connection string like this
<appSettings>
<add key="KhadamatConnectionString"
value="Server=[copy name from Your ServerName of SSMS];Database=AcaService;uid=admin;pwd=mypass;" />
</appSettings>
or
<connectionStrings>
<add name="KhadamatConnectionString" connectionString="Data Source=[copy name from Your ServerName of SSMS];Initial Catalog=AcaService;User ID=admin;Password=mypass;" providerName="System.Data.SqlClient"/>
</connectionStrings>

System.Data.SqlClient.SqlException: Login failed for user XXX

I'm deploying a web application on IIS 7.5, that web app has three kind of bikes for user to choose (Mountain Bikes, Road Bikes, and Touring Bikes). When I click each on it, I got a problems
System.Data.SqlClient.SqlException: Login failed for user XXX
And here is my connection string:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-AdventureCycle-20140110145435;Integrated Security=SSPI" />
<add name="AdvenBikesEntities" connectionString="metadata=res://*/Models.BikesDB.csdl|res://*/Models.BikesDB.ssdl|res://*/Models.BikesDB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\AdventureWorks2012_Data.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework;User Instance=True"" providerName="System.Data.EntityClient" />
<add name="AdventureBikesDataEntities" connectionString="metadata=res://*/Models.CategoriesBikesDB.csdl|res://*/Models.CategoriesBikesDB.ssdl|res://*/Models.CategoriesBikesDB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\AdventureWorks2012_Data.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework;User Instance=True"" providerName="System.Data.EntityClient" />
<add name="AdventureBikeDataEntities" connectionString="metadata=res://*/Models.AdventureBikeDB.csdl|res://*/Models.AdventureBikeDB.ssdl|res://*/Models.AdventureBikeDB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\AdventureWorks2012_Data.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework;User Instance=True"" providerName="System.Data.EntityClient" />
<add name="AdventureBikesDBEntities" connectionString="metadata=res://*/Models.AdventureBikesEntities.csdl|res://*/Models.AdventureBikesEntities.ssdl|res://*/Models.AdventureBikesEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\AdventureWorks2012_Data.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework;User Instance=True"" providerName="System.Data.EntityClient" />
<add name="AdventureBikeDBEntities" connectionString="metadata=res://*/Models.AdventureBikeDB.csdl|res://*/Models.AdventureBikeDB.ssdl|res://*/Models.AdventureBikeDB.msl;provider=System.Data.SqlClient;provider connection string="data source=TRUNGGEORGE-PC\MSSQLSERVER2012;initial catalog=AdventureWorks2012;Integrated Security=True;User ID=trung;Password=tuoi312;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
Could you please help me out of this? Thank you so much for your time :)
As Greg has mentioned, Integrated Security=SSPI means that its using the windows account which is setup for the Anonymous User in IIS. Either one of three things you will need to do to correct the issue:
1) Add the user used by the worker process to the SQL database and assign the appropriate permissions.
2) Change the Connection String to use a predefined user name and password. Use http://connectionstrings.com to find out how to change this.
3) Change the Anonymous authentication credentials or the credentials used by the worker process.
If you need help completing either 1 or 3, let us know and someone will be able to walk you through it.

Adding user and password to Sql Server database

My connection string defined in Web.Config currently indicatea no user or password is needed:
<connectionStrings>
<add name="CinemaxConnectionString" connectionString="Data Source=PCName\SQLEXPRESS;Initial Catalog=Cinemax;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I would like to add user and password, like this:
<connectionStrings>
<add name="CinemaxConnectionString" connectionString="Data Source=PCName\SQLEXPRESS;Initial Catalog=Cinemax;User=cinemax; Password=abc"
providerName="System.Data.SqlClient" />
</connectionStrings>
Obviously, this requires changing some settings in Sql Server to add user and password. What is the best way to do this? I specify I have Sql Server 2005 Express and the current authentcation mode is "Sql Server and Windows Authentication".
Thank you in advance for your help.
It would be nice to see a double take on this: user-interface and code solution.
The below statements would do the job for you.
CREATE LOGIN cinemax WITH PASSWORD = 'abc';
GO
CREATE USER cinemaxUser FOR LOGIN cinemax
GO
GRANT SELECT TO cinemaxUser
GO
GRANT INSERT TO cinemaxUser
GO
GRANT UPDATE TO cinemaxUser
GO
GRANT DELETE TO cinemaxUser
GO