SQL Request connection string error - c#

I have written a WCF service with database connection in Visual Studio 2012. When I deploy the database on my server I get an error:
The server encountered an error processing the request. The exception
message is 'Instance failure.'. See server logs for more details.
I followed the steps from here to help me but it only helped me to an extent.
My connection string seems to be the problem. My connection string is
Data Source=.\\MSSQLSERVER;Database=jarvis;Integrated Security=SSPI;User Id=sa;Password=123
The server that I am using is running SQL Server 2012 Developer edition. What courses this problem and how can I fix this?

Your connection string is currently using Integrated Security=SSPI and also providing a user and password. You should be only using one of those. Integrated Security means that you use the windows authentication method, so it impersonates the windows user and tries to log in with it (so you shouldn't also provide a user and password). On the other hand, you can use the User Id and password, but without Integrated Security.
So, it's either:
Data Source=.\\MSSQLSERVER;Database=jarvis;Integrated Security=SSPI
Or:
Data Source=.\\MSSQLSERVER;Database=jarvis;User Id=sa;Password=123

Trial and error just taught me that the problem was "Data Source=.\MSSQLSERVER;" - It's the double \. That's an escape sequence in C#. Everything worked when I switched the connection string to .\MSSQLSERVER.

Related

IIS seems to not being able to connect using Entity framework provider

I've being trying in vain to solve a problem on a newly created windows server with IIS hosting an ASP.NET application that was copied from another environment. The issue is that I cannot manage to connect to the database when the application tries to open a connection via entity framework.
If this is off topic for SO let me know so I can move to another channel, I thought it belonged here as seems specific to EF.
In detail, I have the following connection strings:
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=LOCALCOMPUTER\SQLEXPRESS;Initial Catalog=xxx;Persist Security Info=True;User ID=yyy;Password=zzz" providerName="System.Data.SqlClient"/>
<add name="MembershipConnection" connectionString="metadata=res://*/App_Code.Membership.Membership.csdl|res://*/App_Code.Membership.Membership.ssdl|res://*/App_Code.Membership.Membership.msl;provider=System.Data.SqlClient;provider connection string="Data Source=LOCALCOMPUTER\SQLEXPRESS;Initial Catalog=xxx;Persist Security Info=True;User ID=yyy;Password=zzz;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient"/>
...
xxx, yyy, zzz of course have the proper values. LOCALCOMPUTER is the FDQN of the local computer, which is not on a domain
The first connection string is for the Microsoft login library, while the second uses entity framework from our code.
When I browse to the site, I can successfully access the login form, and if I try to insert a wrong password i get a message saying so, meaning the application managed to check the database using the first connection string, but when i insert a correct one, i land on an exception as soon as the code tries to create a context.
The underlying provider failed on Open.:
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: TCP Provider, error: 0 - The wait operation timed out.)
In the event viewer it tells me that the user has been authenticated via Authentication Type: Forms , which I assume it means the auth system (the one using ApplicationServices connection string) is working, the stack trace confirms that the error occours when I try to use EF in code, meaning the DB has been used succesfully to check user credentials
note that:
The web app works in other environments
I can connect to the sql server using the credentials via SSMS
I've assigned a local windows account to the app pool that can also access the database, and tried changing to Integrated Security=SSPI
Both .Net 3.5 and .Net 4.8 are installed
The database is on the local machine and has been restored from a dump of the other one, its users have been mapped, and to rule out issues i gave it ample authorisations with dbowner datawriter and datareader
I've been trying to fix this since a couple days checking similar issues on SO with no avail and I don't really know how to proceed, is there something I can do to troubleshoot the issue?
Apologies, I've found out the answer, and it's specific to the code base. Apparently the connection string was being ignored (despite being perfectly usable) in favour of data saved in a table.
Had to contact the previous developer to find out, guess it's a good example of how important is to document your code
I'll close the thread, thanks for all who tried to help

After deployment of win app with SQL Server Express database I got error as "cannot open database login failed"

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

Linq to SQL Connection String for Sql Auth

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.

Can't connect to SQL Server database: Login failed for user 'sa''

I can't simply connect to my database because of this error
Login failed for user 'sa'
Consider these lines of code:
SqlConnection conn = new SqlConnection("Data Source=arohbi;Initial Catalog=SPADA_FIS;Persist Security Info=True;User ID=sa;Password=p#ssword");
conn.Open();
After the execution of conn.Open() I got this weird error message
Login failed for user 'sa'.
Last time I used this setup and connection string and it work perfectly but one day when I try to connect this message is the only response. Still I manage to connect using management studio. The connection from the serverdatabase to my local machine work perfectly. Anyone guys knows the answer.
Things get worst this time. Take a look at these images:
I used same connection string on both sqlconnection but i was confuse why the other one failed?
Connection string used on both:
Data Source=arohbi;Initial Catalog=SPADA_FIS;Persist Security Info=True;User ID=espada;Password=p#ssword
There are a three primary reasons that I can think of off the top of my head that would cause this:
1) The sa user's password has expired or is different than what you have specified.
2) The sa user has been disabled, either by being denied permission to connect to the database engine or having the login disabled.
3) Your instance of SQL server is not configured for SQL authentication.
Whenever you're trying to troubleshoot a problem like this, boil it down to the simplest reproducible case. Right now, you've got a custom client trying to connect and are interpreting exceptions. Try connecting with a stock client (i.e. Management Studio) and see what happens.
That said, other answers here are spot on. Based on the error message that you're getting, either the sa login has been disabled or the password that you're using for it is incorrect. Contact the administrator of the server to find out how you can connect.

Why do I get an SqlClientPermission exception?

I have built a C# WinForms application which accesses a SQL Server 2008 for data manipulation.
The application works fine on the machine that was developed on. However when I copy the EXEs and move it to another computer (Windows XP), I got the following error during the login to the system (in other words, when i access the database).
Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed
Here's my connection string:
Data Source=vmsql;Integrated Security=SSPI;Initial Catalog=ChequeBookInventory
Stack trace is given in a screen shot
Any idea how to fix this issue?!
Most likely, the program is not executed with full trust. Either because the computer is configured like this or you are running it from a network share...
Some more info can be found here.
Grant the executing user rights to the database.
Well It was a combination of things that did the trick...
Setup code level access... I had allow full trust on machine level that network share URL through .NET Fx configuration (Whc i had to install seperately)
Install .NET latest version.. (I stuck to 3.5 ;-] )
Thanks for all the help guys :-)!!
If you want to connect to SQL Server remotely, and don't want use the username and password but Windows Authentication, that's just one way - "AD" ,I think AD might cause more problems (but AD is more secure), and I am really sorry about that my answer is not correct, I found some references about that issue,I think it might be help.
1.How to troubleshoot the "Cannot generate SSPI context" error message
2.“Cannot Generate SSPI Context” error message, more comments for SQL Server
3.“Cannot generate SSPI context” error message, when connect to local SQL Server outside domain
4.Service Principal Names (Windows)
5."Access Denied" error message when you try to access remote resources
that's bad answer bellow:
If you use "Integrated Security=SSPI", that means you can't connect to SQL Server remotely.
if you want to connect remotely, please use "User Id=myUsername;Password=myPassword;" instead of "Integrated Security=SSPI".
(Of course your SQL Server must accept "remote connection")connection string for connecting to data sources

Categories