This is my connection string
{
"Data": {
"PhotoGalleryConnection": {
"ConnectionString": "Server=WINDOWS-B7MJR5T\\SQLEXPRESS;User Id=sa;password=allah;Database=PhotoGallery;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
}
And I am facing this exception
An exception of type 'System.Data.SqlClient.SqlException' occurred in
Microsoft.EntityFrameworkCore.dll but was not handled in user code
Additional information: Cannot open database "PhotoGallery" requested
by the login. The login failed.
It should work after You delete Trusted_Connection=True; from connection string.
If you specify either Trusted_Connection=True; or Integrated
Security=SSPI; or Integrated Security=true; in your connection string
THEN (and only then) you have Windows Authentication happening. Any
user id= setting in the connection string will be ignored. Found in here: When using Trusted_Connection=true and SQL Server authentication, will this effect performance?
Please search services in the window menu, it will show you the local services then go to SQL server services and refresh all, then go to the SQL server management studio and by using SQL authentication please provide username and password, you will be able to use the SQL server. for appsetting.json update, trusted_connection is used for window authentication not for SQL server authentication by using username and password
Related
I have some working code that is currently sitting on our test dev server that connects to an SQL server using Integrated Security/Trusted_Connection at the moment.
I will need to deploy this to a clients server and it will be scheduled to run every hour regardless of if a user is logged on or not.
as the user may not be logged in I assume that the Integrated security will not work.
The credentials I am putting in are the same as those I use to connect to the dev server. I have tried both with the domain "organisation\username" however this does not work either.
SqlConnection myConnection = new SqlConnection("User id=username;" + "Password=xxxxxx; + "Data Source=datasrc;" + "Initial Catalog=catalog; " + "connection timeout=30");
myConnection.Open();
The above code does not work and results in the program 'hanging' before running myConnection.Open()
However putting "Integrated Security=True;" and removing the "User id" and "Password" sections of the string works.
When I try to use "User id=name;" + "Password=xxxxxx;" it does not work and just hangs.
Below is an error message from trying to login with username and password (windows authentication works fine) on the SQL Server 2014 Management Studio
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)
The network path was not found"
Integrated Security=True; means that the current credential being used to run the application pool will also be used to login to the SQL database. It doesn't make sense to use Integrated Security=True; and a User ID + Password. One or the other.
So, if your IIS instance is using an application pool logged in by User123, and the .NET application sitting on that IIS instance connects to a SQL database, then that .NET application will attempt to login to the SQL database using User123, so long as Integrated Security=True;. Typically people do this to ensure no plaintext passwords are present in the web.config, for security reasons. EDIT: you can see which user the application pool is using by right clicking the application pool in IIS manager and going to 'Advanced Settings'.
If it only works when you have Integrated Security=True; then that means only that user has permissions to access the SQL database. I would open up SSMS, navigate to the SQL database, and review the Logins under the Security navigation tree. Keep in mind there is a Login for the database server, as well as for the database itself, so you may have to configure this in two places.
I have a database on a local network.
I can connect to the database in SSMS:
But when I want to connect to the database by this connection string in c#:
"Data Source=192.168.0.3,14330;Network Library=DBMSSOCN;Initial Catalog=master;Integrated Security=True;User ID=sa;Password=123456789;"
I get the following error:
Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
Your are telling sql server to use integrated security, ie windows security, however you trying to use a username and password
turn integrated security off, see the below example
"Data Source=192.168.0.3,14330;Network Library=DBMSSOCN;Initial Catalog=master;Integrated Security=False;User ID=sa;Password=123456789;"
Pertinent information
If User ID and Password are specified and Integrated Security is set to true, the User ID and Password will be ignored and Integrated Security will be used.
You can find more information on connection strings here, SqlConnection.ConnectionString Property
Update
maybe this question may help you more How to get the connection String from a database
Update 2
For more in depth troubleshooting, there is a great resource here How to Troubleshoot Connecting to the SQL Server Database Engine
I made a win forms app with SQL Server Express with Visual Studio 2010.
When I deploy my app by right click on Solution Explorer selecting Properties and then Publish and following all the procedure.
When I install on other system, error occured. The error was:
cannot open database [dbname] login requested by user [username] failed...
I googled much but no use. I think it might be in connectionstring, if it is so, what and how should be connectionstring or any other alternative.
If you have Integrated Security = true in your connection string you will have to provide a sql server login and a database user in SQL Server for your users. Alternatively, you can set up a specific SQL Server login and database user for your app, grant it least-privaledged permissions in SQL Server, and then specify it in your connection string as user=myuser;password=mypassword;
Then remove the integrated security = true portion altogether.
1st- check if your connection string is correct and make it specific like dont use dot. try to use IP address on your server name(dont forget to include \SQLexpress if needed). also if u are using windows authentication(without user id and password) you need to add on the connection string: "integrated security=SSPI"
2nd- off firewall. firewall blocks all remote connection
3rd- check hardware, ping the server and make sure the client can see the server
tI'm using Sql Server with Windows Authentication enabled. Recently I added a dropdown to allow for different connections. One of them uses SQL Authentication.
I consulted msdn and it seems all I need to do is add a Username and Password entry to my string.
http://msdn.microsoft.com/en-us/library/aa905872(v=sql.80).aspx
My windows authentication string :
Data Source=PC\Slike;Initial Catalog=db_slike_articles;Integrated Security=True
The second string I added for SQL Authentication :
Data Source=Data Source=PC\Dev;Initial Catalog=db_dev_articles;Integrated Security=True;User ID=root;Password=rootpwd
For some reason when I choose the 2nd SQL connection it's throwing an SqlException that login failed with my PC\Slike username. The connection string is the second one with the User ID and Pwd, I don't understand why it's trying to connect against my local account.
The second string is located on a remote machine, is there something I have to enable to switch from Windows Auth to Sql Auth or does specifying the the credentials within the string is enough?
Thanks
when using SQL Authentication, remove this from the connection string:
Integrated Security=True;
there is a web site listing all possible/supported syntax of connection strings for all database engines, I can't find it now, connectionstrings.com does not load properly.
I saw this link non sa user sql connection string.
This is giving datasource name and userid and passworkd and database name. But I have doubt about datasource name :Dynamic GP 2010. I am bit confused using this connection string:
string connection = "data source=Dynamic GP 2010;initial catalog=TWO;integrated security=False;User ID=client;Password=123";
This is giving error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Let me know which datasource I have to use. Is GP datasource name (or) sql datasource name.
Econnect must use a trusted connection. You cannot pass a username and password into the connection string. To add a user that does not have sa access, add the domain user to sql server with the appropriate permissions. You will also need to configure the econnect setup to allow the user to access sql through econnect. Secondly, if you are setting this up on a SQL server that has not been setup to allow incoming connections via non-windows connection, this will need to be set up as well. This may be due to not having mixed auth mode on. See this article to try and fix
string connectionString = #"Data Source=localhost; Integrated Security=SSPI;Persist Security Info=False; Initial Catalog=TWO;";