I have my web.config like this:
<connectionStrings>
<add name="myConnectionString"
connectionString="Data Source=PC1;
Initial Catalog=BD1;
Integrated Security=SSPI"
providerName="System.Data.SqlClient"/>
<add name="myConnectionString2"
connectionString="Data Source=PC2;
Initial Catalog=BD2;
Integrated Security=False;
User Id=usuario;
Password=pass"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I can connect to the first one, a database with my windows user auth, but i can not to the second one, a database with other windows user auth.
Error: Login failed for user 'usuario'.
I can run Sql Server as other user, and i can connect to the database.
Picture how i run SQL server
Related
I have two servers: AppServer with IP 192.168.1.2 and DBServer with IP 192.168.1.3
On DBServer I have the database EMSMVC in the DBSERVER\SQLEXPRESS instance. The database is working.
On the AppServer in web.config I have:
<add name="DefaultConnection"
connectionString="Data Source=;Initial Catalog=EMSMVC;Integrated Security=True;Server=192.168.1.3;user id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
<add name="EMSMVCEntities"
connectionString="metadata=res://*/Models.EMSModel.csdl|res://*/Models.EMSModel.ssdl|res://*/Models.EMSModel.msl;provider=System.Data.SqlClient;provider connection string="data source=DBSERVER\SQLEXPRESS;initial catalog=EMSMVC;integrated security=True;Server=192.168.1.3;user id=admin;password=DBSERVER\admin;multipleactiveresultsets=True;application name=EntityFramework""
providerName="System.Data.EntityClient" />
When I browse the app in the AppServer I get the following error:
[SqlException (0x80131904): Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.]
However, I'm not trying to connect using Anonymous logon.
Your connection string is flawed with several problems:
<add name="DefaultConnection"
connectionString="Data Source=;Initial Catalog=EMSMVC;Integrated Security=True;Server=192.168.1.3;user id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
You have both a Data Source (with no value) and a Server - you should use one or the other - but not both. Both basically mean the same thing - you neither of them is specifying the \SQLEXPRESS instance name ....
You're specifying an User Id (and password) in the connection string - but also Integrated Security=True, which means use the built-in Windows authorization - again: if you want to use User Id; then you must NOT also specify Integrated Security at the same time - this setting will take precedence over the specified User Id.
So your connection string should really be:
<add name="DefaultConnection"
connectionString="Data Source=DBSERVER\SQLEXPRESS;Initial Catalog=EMSMVC;User id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
or using the IP address instead of the machine name:
<add name="DefaultConnection"
connectionString="Data Source=192.168.1.3\SQLEXPRESS;Initial Catalog=EMSMVC;User id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
or if you prefer the Server= instead of the Data Source= setting:
<add name="DefaultConnection"
connectionString="Server=192.168.1.3\SQLEXPRESS;Initial Catalog=EMSMVC;User id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
Initially, my project (running on localhost with SQL Server Express) had a connection string to the database Test1:
<connectionStrings>
<add name="TestContext"
connectionString="data source=.\SQLEXPRESS; Integrated Security=SSPI; Initial Catalog=Test1; User Instance=true"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
Now, I want the same project uses a different database: Test2.
So I've changed the "Initial Catalog" in the connection string to Test2.
But, to my surprise, when I execute the application, the Test1 database is still the one to be used.
What am I doing wrong?
I've already try to stop/start the IIS and delete the "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" folder with no success.
I am creating a website, but in the database I use windows authentication.
I know that you use this for SQL authentication
<connectionStrings>
<add name="NorthwindContex"
connectionString="data source=localhost;
initial catalog=northwind;persist security info=True;
user id=sa;password=P#ssw0rd"
providerName="System.Data.SqlClient" />
</connectionStrings>
How do I modify this to work with windows authentication?
Replace the username and password with Integrated Security=SSPI;
So the connection string should be
<connectionStrings>
<add name="NorthwindContex"
connectionString="data source=localhost;
initial catalog=northwind;persist security info=True;
Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
For connecting to a sql server database via Windows authentication basically needs which server you want to connect , what is your database name , Integrated Security info and provider name.
Basically this works:
<connectionStrings>
<add name="MyConnectionString"
connectionString="data source=ServerName;
Initial Catalog=DatabaseName;Integrated Security=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Setting Integrated Security field true means basically you want to reach database via Windows authentication, if you set this field false Windows authentication will not work.
It is also working different according which provider you are using.
SqlClient both Integrated Security=true; or IntegratedSecurity=SSPI; is working.
OleDb it is Integrated Security=SSPI;
Odbc it is Trusted_Connection=yes;
OracleClient it is Integrated Security=yes;
Integrated Security=true throws an exception when used with the OleDb provider.
For the correct solution after many hours:
Open the configuration file
Change the connection string with the following
<add name="umbracoDbDSN" connectionString="data source=YOUR_SERVER_NAME;database=nrc;Integrated Security=SSPI;persist security info=True;" providerName="System.Data.SqlClient" />
Change the YOUR_SERVER_NAME with your current server name and save
Open the IIS Manager
Find the name of the application pool that the website or web application is using
Right-click and choose Advanced settings
From Advanced settings under Process Model change the Identity to Custom account and add your Server Admin details, please see the attached images:
Hope this will help.
This is shorter and works
<connectionStrings>
<add name="DBConnection"
connectionString="data source=SERVER\INSTANCE;
Initial Catalog=MyDB;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Persist Security Info not needed
If anyone comes looking for asp.net core, we will have to add connection string in appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Server=SQLServer\\Instance;Database=MYDB;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Source: add windows authentication sql server connection string
I'm trying to use bellow method to initialize my database which is hosted on one of Microsoft Azure's servers.
WebSecurity.InitializeDatabaseConnection("DefaultConnection","UserPacient", "PacientID", "PacientUsername", true);
The connection string looks like this
<add name="DefaultConnection" connectionString="Data Source=servername;Initial Catalog=DBName;Persist Security Info=True;User ID=username;Password=***********" providerName="System.Data.SqlClient" />
When I ran the application it throws
Login failed for user 'HelpMed'.
Any idea on why this error??
I need to specify that from SSMS I can connect and access the database from Azure...
I'm creating a simple ASP.NET MVC 4 application using Entity Framework and code-first. With SQL Server Express 2012, everything works fine when using Windows Authentication:
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; AttachDbFilename=|DataDirectory|myDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
However, when using the following for SQL Server Authentication:
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; AttachDbFilename=|DataDirectory|myDb.mdf;Integrated Security=False; User Id=mysa; Password=mysapassword" providerName="System.Data.SqlClient" />
I receive an error:
"Login failed for user 'mysa'" ProviderIncompatibleException.
Am I missing something?
Is it possible that your *.mdf file is not attached to sql server instance?
Try attaching the myDb.mdf file to your database with SQL Management Studio and the change the connection string to
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; Category=myDb;Integrated Security=False; User=mysa; Password=mysapassword" providerName="System.Data.SqlClient" />
and don't forget to give the appropriate rights to your user