System.Data.SqlClient.SqlException: Login failed for user XXX - asp.net-mvc-4

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.

Related

Retrieving default database connection string in code

I am working with the existing structures used by the dev team at my current company. In order to change connection strings within the application, the team creates an XML node called "defaultDatabase" (see below):
</configSections>
<dataConfiguration defaultDatabase="Development" />
<connectionStrings>
<add name="Development" connectionString="Data source=DVHQSQL01; Initial Catalog=db; User ID=id; Password=password"/>
</connectionStrings>
...there will be more connection strings in the XML for different server environments (not shown here, but "Testing", "Staging", "Production", etc)
I am creating a class with different functions that use the default connection. I know one route is through ConfigurationManager as shown here:
https://social.msdn.microsoft.com/Forums/en-US/9a8c9f5a-092e-4c4a-87bb-9f35d8f55da1/get-connection-string-from-appconfig-file?forum=adodotnetdataproviders
This is great if you can change the connection string name in code, but we use the defaultDatabase node to be able to change from different environments without rebuilding.
Does anyone have experience with this methodology? How do I get the correct connection string using the defaultDatabase node?
Just set the default connection in the connection strings area:
<connectionStrings>
<add name="default" connectionString="..."/>
</connectionStrings>
If you have further connections you can add them in the same way:
<connectionStrings>
<add name="default" connectionString="..."/>
<add name="special1" connectionString="..."/>
<add name="special2" connectionString="..."/>
</connectionStrings>
You can have as many connectionStrings as you want in your config, all you have to do is give them different names.
<connectionStrings>
<add name="default" connectionString=""/>
<add name="anotherOne" connectionString=""/>
...
</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>

how to handle database reallocation for dotnetnuke website

i have a website that used to run on sqlexpress data base i changed my server and it stopped running i ran it using visual studi and IIS but it eith gives me error 404 or error 503 i think the problem is in my webconfig sql string connection her is my code:
<connectionStrings>
<add name="SiteSqlServer" connectionString="Data Source=localhost;Initial Catalog=ULTRA; User ID=admin;Password=123" providerName="System.Data.SqlClient" />
<add name="SiteSqlServer" connectionString="Server=(local);Database=DotNetNuke;uid=;pwd=;" providerName="System.Data.SqlClient" />
-->
<!-- Connection String for SQL Server 2008/2012 Express -->
<!--<add name="SiteSqlServer" connectionString="Data Source=localhost;Initial Catalog=ULTRA; User ID=admin;Password=123" providerName="System.Data.SqlClient" />-->
<!-- Connection String for SQL Server 2008/2012
-->
<!--<add name="SiteSqlServer" connectionString="Server=(local);Database=DotNetNuke;uid=;pwd=;" providerName="System.Data.SqlClient" />-->
</connectionStrings>
<appSettings>
<!-- Connection String for SQL Server 2008/2012 Express - kept for backwards compatability - legacy modules -->
<!--<add key="SiteSqlServer" value="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True" />-->
<!-- Connection String for SQL Server 2008/2012 - kept for backwards compatability - legacy modules
-->
<add key="SiteSqlServer" value="Server=(local);Database=DotNetNuke;uid=;pwd=;" />
would someone please help me to tell me what is wrong?
You have your connection string defined multiple times in the ConnectionStrings section of the web.config. Which is the proper connection string?
EDIT:
You likely have an issue with the PortalAliases and your IIS configuration. What is the URL that you are trying to access the website using? Make sure that URL is listed in the PortalAliases table, also make sure that IIS will respond to the URL as well.

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

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

NServiceBus SqlTransport - Where timeout manager should be run?

We are currently setting up NServiceBus with SqlTransport. Do we need use distributors in our test environment ? We have 2 clustered node are running the same application. Where timeout manager should be run in this scenario ?
The distributor is only used for MSMQ transport, see http://particular.net/articles/load-balancing-with-the-distributor section "When to use it?".
Updated:
Timeout manager runs on all endpoints connecting to the same sql database as the transport to avoid DTC.
Here is an example config:
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True" />
<add name="NServiceBus/Persistence" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True" />
</connectionStrings>
You need to reference NserviceBus.NHibernate, see http://particular.net/articles/relational-persistence-using-nhibernate---nservicebus-4.x for more info.