Deploying ASP.NET membership to Godaddy - c#

I'm trying to deploy a website using ASP.NET membership and the hosting company is godaddy. Problem is that for some reason an error is being thrown when I log in. I've modified some pages for testing purposes to see if I can pull data from the database and it works fine. So I know it's mapping to the proper source. The error I'm receiving is the following:
"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)"
Any help would be much appreciated.

It sounds like something is using the LocalSqlServer automagic connection string still. I'd add<remove name="LocalSqlServer /> to your <connectionStrings> and see what blows up.

When you setup membership it normally adds another connection string to your web.config. I think it creates a key in the web.config called ApplicationServices that contains the connection string that the membership classes will use (I think this depends on what membership provider you are using). When you checked the connectionstring did you also check that one?

When you use membership asp.net creates a SQL Database called ASPNETDB.MDF in the App_Data folder which you will need to ensure is set up correctly on the host as you would have done with your main database.
You'll also need to amend the additional connection string in your web.config file so that it points to this database.

Membership settings in web.config can be configured to use any connection string that is defined in web.config. If your membership tables are in the same database as the rest of your tables, I imagine you shpould be able to use a single connection string for everything. That is what I have been trying to set up on my own GoDaddy-hosted website lately, and that is what reading MSDN's documentation suggests should be possible. The "membership" section of "system.web" has a "providers" section, and "add" for that section has a "connectionStringName" attribute.

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

Azure Hybrid Connection string

I have successfully created an Hybrid Connection between Azure and an on-premise resource. I see "Connected" in both the Azure Portal and Hybrid Connection Manager.
When I run my .NET code local in Visual Studio with the connection string "AppServer://MyPC:5162/AzureOeApi" everything runs fine but when I run it in Azure, I get a connection error (it can't see the on-prem end-point).
Do I need to change my connection string when running in Azure to force it to go through the Hybrid Connection or will it be handled automatically?
No need to change connection string.
We had similar issue - connection was "Connected", but no requests whould go through. You need to use fully qualified domain name in configuration of hybrid connection.
Please also read this question - similar question
I've been struggling with this problem for a whole day and finally I had a breakthrough: in my original connection string I was referring to [DB_SERVER]\[INSTANCE], having correctly configured the DB instance to listen to a given TCP port [PORT].
With this setup the Hybrid Connection was 'Connected' but I was getting the exception:
ExceptionMessage: The underlying provider failed on Open. -InnerExceptionMessage: 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)
It turns out that the connection string needs do explicitly refer to the port number (instead of the DB instance) using the syntax [DB_SERVER],[PORT] (mind the comma!).
Unfortunately Microsoft does not document this subtle detail....

ASP.NET MVC failure to create database [duplicate]

This question already has answers here:
Cannot Connect to Server - A network-related or instance-specific error
(54 answers)
Closed 6 years ago.
I'm new to ASP.NET MVC and was just messing around with it and trying to see how it works. So I decided to make a query to the database accessed with the default ApplicationDbContext. Normally, if the database hadn't been instantiated before that, this query would make sure to first create the database and then make the query, right? Well, here's what I did:
// This is the default Index action in the Home controller:
public ActionResult Index()
{
var db = new ApplicationDbContext();
var usersCount = db.Users.Count();
return View();
}
I know that the query is pretty meaningless but the sole purpose of it was for it to generate the database. The thing is it that it doesn't. I get a System.Data.SqlClient.SqlException when trying to execute the query (second line of the method).
Even when checking the App_Data folder I see that the database isn't created. What could be the cause of this? Strange thing is that this works on my desktop computer, but not on my laptop. But I did notice that when I put an invalid Data Source(ex. Data Source=.) in the connection string I get the same exception on my desktop computer. So maybe something is happening with the LocalDb that's causing this behaviour.
The connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-DefaultProject-20160731061747.mdf;Initial Catalog=aspnet-DefaultProject-20160731061747;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
This is the full exception:
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: 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.)
I would be very grateful if someone can come up with a solution for this!
P.S: Everything works fine on my laptop if I change the Data Source to my SQL Server Express server name.
Sounds like your LocalDb instance isn't installed. This is a bit of a "dev attachment" version of SQL that's installed with certain versions of Visual Studio and might have been de-selected or just plain not included perhaps if the original install was older and has gone through upgrades, etc.
This post gives a decent explaination: How to install localdb separately?
Basically google for SqlLocalDb.msi and follow the instructions.
I generally prefer Express over localDb anyway, but that's up to you.
Also note that connection strings are considered "loose" information in the web.config for MVC stuff. That is, they tend to be specific to the machine, so if you're changing machines (or working on a team), your machine is likely to have a different connection string (or a local copy/partial of web.config).

"Can not find server or is not available" on test server but not while debugging

I keep getting an error when trying to access the database from a web site it returns an error that it can't find the server or it's inaccessible.
Now I did a search and I found many possible reasons - I turned on named pipes and also did what this link suggested (i.e. set the IP addresses to "enabled") yet I'm still getting the error.
Error SqlException: System.Data.SqlClient.SqlException (0x80131904):
Error An error has occurred with the network or the occurrence when
connecting to SQL Server. Can not find server or is not available.
Verify that the instance name is correct and that the configuration of
SQL Server allow remote connections. (provider: Named Pipes Provider,
error: 40 - Could not open a connection to SQL Server) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) at
I also downloaded this little app and I copy/pasted the connection string from the web.config used in IIS for this site and the app is able to connect and query the same database being targeted by the web site.
And, as the title says, this error is utterly missing when I debug it in VS2010. What could be causing this error when launching from the server?
Edit: the connection string includes a user name and password (it's not Windows Authentication).
Most likely a security issue. If using windows authentication then make sure the thread pool that the web application is running as has sufficient DB access\privileges.
The issue is that the web.config references another config file
<appSettings file="config/dev.config">
and so the connection string in web.config is ignored over the one in dev.config - an error to have it in both (the one on the test server was created by someone else and worked on static pages - it only failed when the website had to query the database), that's why the version in Visual Studio was running fine.

SqlConnection problem

My sqlconnection is
SqlConnection(#"Data Source = John\Administrator; Initial Catalog = TicketingSystem; Integrated Security = true;");
I try to connect to the server but i cant this error pops up
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 think that the error is in the Data Source but I cant find it. When I open Microsoft SQL Server Management Studio it says that my server is "John" and the Connection is "John\Administrator" so please help me.
if the server is actually called 'John', then that is your data source. When you're running locally, you could probably just set Data Source=(local), tho.
Other than that, you'd need to specify a user to connect with
http://connectionstrings.com/
An easy way to get your connection string is
create a file called x.udl
double click on it
Follow wizard
open x.udl file in notepad
and inside you will find your connection string.
When I open Microsoft SQL Server
Management Studio it says that my
server is "John" and the Connection is
"John\Administrator" so please help
me.
That means you're logged on to your server's default instance (John) as Administrator. Remove the \Administrator part, and you should be good to go!
var cn = new SqlConnection(#"Data Source = John; Initial Catalog = TicketingSystem; Integrated Security = true;");
You can get your connectionstring from SQL Server Management Studio from the properties window.
Just click on the John\Administrator node, then press F4 to open the properties window, and search for the connection string there...
The Integrated Security=True part of your connection string means "connect as the current user". When you run an asp.net page, the current user by default is a special ASPNET account. You can "impersonate" a different user, but I'm guessing you haven't done that and the ASPNET user doesn't have access to your database.
It's possible that your server isn't configured to allow remote connections. You can check this in the SQL Server Configuration Manager tool.
Have a look here too.
Your Data Source is the server. So you only need "John", not "John\Administrator", that's not a valid data source. You're using integrated security which means it will use the same username as the program is running under and it's credentials, if it's on the domain.
Data Source = John\Administrator
Specifying John\Administrator as your Data Source, means ADO should connect to the SQL instance named "Administrator" on the server "John". Although instances are quite useful, I don't think that's what you want. (SQL Instances allow you to run multiple copies of SQL Server on one server)
As "d." mentioned, you will need to change Data Source to the correct server name or (local) ((local)\SQLEXPRESS if it's SQL Express).
Also, Integrated Security=true means that the user running ASP.NET, or at least the AppPool, will need access to the database. (The default is NETWORK SERVICE on pre-Windows 7, IUSR / IIS_USRS on 7).
If, however, you use ASP.NET windows authentication with <identity impersonate="true" /> then the user accessing the site will need access to the database.
Create a file called x.udl
Double-click on it
Follow the Wizard
Open x.udl file in notepad
and then you will find your connection string inside.

Categories