Not able to access the SQL Server - asp.net

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.

Related

Can post to server DB from localhost, but when published to server I get "error: 52 - Unable to locate a Local Database Runtime installation."

I have a simple web app that interacts with a Microsoft SQL Server 2016 Standard Edition that is hosted on it's own server, in the same environment. When I run the app locally, it connects just fine and posts to the DB with no problem. After I published the app to our app hosting server I get the following error:
error: 52 - Unable to locate a Local Database Runtime installation.
I'm wondering why it is even talking about a local database when I am connected to a DB on a server, which was initially working. I know the connectionString works because it connects to the DB and posts just fine from localhost.
<connectionStrings>
<add name="PickemContext" connectionString="Data Source=ISSQLTEST01; user id=pickem; Password=pickem"
providerName="System.Data.SqlClient" />
</connectionStrings>
Here is the error.
The system cannot find the file specified
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[Win32Exception (0x80004005): The system cannot find the file specified]
[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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
And it keeps going with more stuff in the stack trace.
How can I go about troubleshooting this? Its confusing to me that it works and posts to the DB just fine from localhost but throws an error talking about localDBs when trying to post from the hosted app. When looking at the table data displayed on the hosted app, it loads everything in fine, all the data that's in this table. The problem just seems to be with posting.
Ok I fixed the issue. The issue was not my connection string in Web.config. When I was making the app, I had to add some functionality to the Create method in the controller, and I had set a "conString" String variable because parts of this method needed the connectionString. This variable was still holding the original connectionString which points to a localDB. I just replaced that with the proper connectionString and now it is all good.

Why does connection string has to be in the client side project and not DAL?

Well, I have two projects:
Blog.Core (a class library project for my entites as well as data access code)
Blog (ASP.NET MVC Project)
I installed EF in Blog.Core. Then added reference to Blog.Core in Blog. I have specified my connection string in Blog.Core since this is my DAL. Now when I run the project I get the following error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code
Additional information: 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 deleted the connection string form Blog.Core and placed it in Blog project, and it works. Why is that? Doesn't this break the architecture because client-side has the database connection string? I mean isn't that correct that only DAL should be responsible for connection strings and database operations. Why was my first (and, according to me, more logical) solution not working?
There has been lots of argument about this one and you can refer to this thread C# DLL config file

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.

trouble connecting to LocalDB in Visual Studio

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.

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