trouble connecting to LocalDB in Visual Studio - asp.net

I'm going through the Contoso University tutorial found here on asp.net and can't get past the first part due to connectionString problems.
I'm getting this error message after i enter the connection string and try to view the database.
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: SQL Network Interfaces, error: 50 - Local Database Runtime
error occurred. Cannot create an automatic instance. See the Windows
Application event log for error details.
I was looking at this msdn blog which mentions the same error under the "Deploying LocalDB on IIS Server " section but i honestly have no idea what it wants me to do.
How can do i fix this error? Is it a problem with the tutorial or am I missing something?
Thanks in advance.

Any chance it is because you forgot to double-escape the backslash? Did you try this:
"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Or even better, you could just use the # mark to disable character escaping for the entire connection string:
#"Data Source=(LocalDB)\v11.0;Integrated Security=true"

Here is what i do in order to fix this problem
You need to install the sql server local db
Copy the local server of your local db in case you don't know here is how to find the local server name(You need to copy the highlighted part)
Update the local server name in the connection string in the web.config file of the Contoso Project
Note that you only need to update the server name in you connection string do not replace the whole connection string with the server name.
Re run all the migration one by one like this
update-database -TargetMigration MigratonName
Build the project and run it.

Change application pool identity from ApplicationPoolIdentity to LocalSystem in IIS for your website application pool and IntgretedSecurity = true in config
will help you.

Related

ASP.NET 4.5 Connection string to SQL Server 2019 - "An error occurred while communicating with the database"

So my company has an old legacy .NET 4.5 web application running on IIS (version 8.5.9600.16384) in which it's application database resides on Microsoft SQL Server 2014 (SP3)... This works perfectly fine.
However (due to decommissioning / upgrades) we want to move the database to our SQL Server 2019 Server. So I took the original .NET package and re-imported it >> during the wizard I entered the SQL Server 2019 Server / db path and renamed the solution name with '_TEST' suffix >> then restarted IIS. The resulting connection string looks like this (as expected / mirroring the original working one however with the new server / db / uname):
connection string in IIS
When I go to test logging in to the web application (via IE11), I get the following "an error occurred while communicating with the database" error after clicking login:
Error message
We also tested the same exact SQL Server 2019 connection string through Powershell on this same web server and we are able to connect into the database, so it would seem that there's some mechanism failing inside the .NET application whether there's a configuration or driver not quite right somewhere.
Does anyone have any suggestions as to what I could potentially try next or what the issue might be here?
It seems you need to use the correct connectionstring. I know it works in your previous sql server 2014. Please follow the below steps to get the connection string, and replace it in your web.config. And the settings sync to your IIS.
If there also have any errors, you can update your post.
Steps
open your vs2019, and open sql server object explorer .
Add new server, and type the information to connect your sql server 2019.
After connect to the sql server, please click the Properties to copy the Connection string.

Classic ASP connecting to localdb for SQL Server

Can anyone explain why this works
Conn.Open "Provider=SQLOLEDB;Server=tcp:myazurename.database.windows.net;Database=People;Uid=MyUid;Pwd=MyPwd;Encrypt=yes;"
and this doesn't
Conn.Open "Provider=SQLOLEDB;Server=(localdb)\v11.0;Database=People;Uid=MyUid;Pwd=MyPwd;Encrypt=yes;"
I copied my live azure database locally for dev work in Classic ASP and the error message is
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).] SQL Server does not exist or access denied.
Azure SQL server version: 11.0.9231
Local SQL server version: 11.0.2318
I can connect using the same details on SQL Server Management Studio so its not a user permissions thing...
Under Security for the server, the user has public server role, the user mapping for the 'People' database is everything except db_denydatareader and db_denydatawriter.
I have also tried (localdb)\\v11.0 which doesn't make a difference.
Any ideas?
OK so I believe the answer is as follows: It doesn't like (LocalDb)\V11.0 it wants a proper instance name like you said in the first place. MACHINENAME\INSTANCENAME OR localhost\INSTANCENAME which I am using as this is going to be replicated for other devs. Also, you DONT NEED two back slashes! My problem is I somehow didn't have a local instance installed. Thanks or your help #Lankymart

Win32 Exception Error: The Parameter was incorrect after deploying to GoDaddy

I have ran into an issue with this error. Here is the rest of the StackTrace (the first line of it, let me know if I need to provide the complete StackTrace )..
[SqlException (0x80131904): 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: SQL Network Interfaces, error: 25 - Connection string is not valid)]
I can connect to the database through SSMS, but when I go to the site to register I get the error that I mentioned. A brief run down of what I created. Its an Web application from the template in VS2013. I took the database that it created with the following tables..
and I added a couple of tables of my own. Everything worked fine off of my laptop before publishing the website. GoDaddy is unsure of what is causing the issue and are looking into it. They ran tests and can connect to the database. But when you go to register on the website, its throwing that error.
I have doubled checked and rechecked my connection string, its the same one that I use to connect to the database through SSMS.
Here is my connection string, minus the username and password, datasource etc...
<add name="DefaultConnection" connectionString="Data Source=**********;Initial Catalog=******;Persist Security Info=True;User ID=*******;Password=*******" providerName="System.Data.SqlClient" />
I know the error says invalid connectionstring, but I was told that it was correct.
Any idea's?
UPDATE
I did some digging around about deploying a membership database and found that when I generated scripts that I should have generated schema and data. So I went and removed the current tables and scripted out my local database(the one that works) and generated the schema and data. Then I ran it against the database, double checked that I had data in the database, which I know do. But when I went to register, I got the exact same error.

Not able to access the SQL Server

i'm currently trying to add a login control to my program, but the problem is, whenever i try to login/register or use the asp configuration tool and go on the security tab, it won't work. It says it's not connecting to the provider. I am new to programming and don't really know what to do with web.config's and for the membership provider to work. Simply put, I can't utilise an SQL server. whenever i try using the aspnet_regsql.exe, it gives me an error saying it can't access it. And whenever i try to create or connect to one, same error. Please help. Thank you in advance.
edit:
I get this error whenever i try registering a user with a blank web.config.
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: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
Also, whenever i try adding a new sql server database, it jut gives me an error saying the sql server was not found or inaccessible
I created the login control by following this tutorial
http://msdn.microsoft.com/en-us/library/879kf95c(v=vs.100).aspx
Usually this error occurs when you use SQL authentication by providing user name and password within the connection string, instead of windows authentication. But SQL authentication was not enabled at SQL server level.
Please refer following post SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified to enable SQL authentication at server.

Database is not accessible on server but working well on localhost

I have developed my first website in ASP.NET with C#. It's a small website which uses Microsoft SQL server 2008 for database and I've deployed it on a free hosting site www.somee.com. It's database is working well on my computer but when I try to access the database on server it gives following 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: SQL Network Interfaces,
error: 26 - Error Locating Server/Instance Specified)].
I have updated connection string of the database in web.config and I've used getConString() method for accessing connection string like this:
public string getConString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
}
What can I do to solve this problem.
Wbsite url is: www.easyways.somee.com
Thanks all of you for your support. I got the solution for my problem. Actually I did something wrong either in creating a database or in using connection string.
Now I recreated a blank database and then I executed the SQL script that I created for my database by navigating to "User -> Managed products -> MS SQL -> Databases -> (Database name) -> New SQL query from file". And also updated the new connection string in web.config file.
This is the connection string I used now:
"workstation id=dataeasyways.mssql.somee.com;packet size=4096;user id=easyways_db;pwd=********;data source=dataeasyways.mssql.somee.com;persist security info=False;initial catalog=dataeasyways"
Your hosting provider provides the connection information for you (in the case of your hosting provider you can see their Help Page here, which shows you how to connect to their DB.
Basically it boils down to logging into their control panel.
In "User menu" navigate to "User -> Managed products -> MS SQL -> Databases -> (Database name)".
Also remember that since this is a remote database there is a small chance that its firwalled from the outside world and only local webservers can access the database.

Resources