Website cannot establish connection to the sql on server - c#

The website runs perfectly fine on my local computer with connection string containing database information of already hosted server. but when i upload the website on the server i get this error. the main page of the website is loading but the other features that has sql connection accessibility are not.
System.ComponentModel.Win32Exception: Access is denied
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: 56 - Unable to load the SQLUserInstance.dll
from the location specified in the registry. Verify that the Local
Database Runtime feature of SQL Server Express is properly
installed.)]
My local default connection string is
<add name="defaultconnection" connectionString="Data Source=(LocalDb)\mssqllocaldb;Initial Catalog=aspnet-fuzzzz-20160406102902;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-fuzzzz-20160406102902.mdf" providerName="System.Data.SqlClient" />
Apart from that i have the entity framework model connection string that contains sql authentication of a remote server that contains data..
Revised and additional information -
my filter looks like this could it be the server is by default taking my default connection string instead of my entity framework connection string
public SimpleMembershipInitializer()
{
Database.SetInitializer<UsersContext>(null);
try
{
using (var context = new UsersContext())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}
}

Related

A network-related or instance-specific error occurred while establishing a connection to SQL GRAPH API ADO

I am currently creating an application with the Graph API and with access to the AD in .NET ASP, everything works correctly in debug mode, but when trying to publish it in an IIS or in Azure as WebApp the error occurs after logging in with the account O365 and redirect to my homepage:
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)
That happens when trying to generate the cache:
private ApplicationDbContext db = new ApplicationDbContext();
//mas codigo aqui
.
.
.
Cache = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == userId);
this.Deserialize((Cache == null) ? null : MachineKey.Unprotect(Cache.cacheBits, "ADALCache"));
The db was generated in an automatic way, so I don't know how it works quite well:
<add name="DefaultConnection"
connectionString="Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication2-20190809024809.mdf;User Instance=true;Initial Catalog=aspnet-WebApplication2-20190809024809;Integrated Security=True"
providerName="System.Data.SqlClient"/>
Already try to add the instance MSSQLLocalDB including replace (localdb) with v11.0, the np pipe, change to the name of the server in an IIS and none of this works still marking the same error.
In the case of Azure I understand that there is no localdb so I don't know how it would have to be modified to make it work
I also tried to connect a server but the program itself creates a .mdf:
WebApplication2.Models.ApplicationDbContext
and
WebApplication2.Models.ApplicationDbContext_log

How to create a EF code first database on different location other than LocalDb

I am developing MVC 5 application with MSSQL Server 2014, which is using 2 databases. One using Database first approach and one using code first approach(default database for users registration and roles in MVC 5).
When I deployed the application on our production server which is providing SQL server 2008, the code first database gives the following error on User Registeration.
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 get a local application data path. Most probably a user profile
is not loaded. If LocalDB is executed under IIS, make sure that
profile loading is enabled for the current user. )
So, I thought that since production server is using SQL Server 2008, so may be it won't be able to create a LocalDb, so I changed the connection string for my code first database as follows;
<connectionStrings>
<add name="PUConnectionString" connectionString="Data Source=**my server name**;AttachDbFilename="|DataDirectory|\aspnet-web erp-20150603105840.mdf";Initial Catalog="aspnet-web erp-20150603105840";UID=**my user name**;PWD=**password**;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
and my identitymodels.cs code is:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("name=PUConnectionString", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
Then it gives the following error:
System.ArgumentException: Invalid value for key 'attachdbfilename'.
at the following line of register method in AccountController
var result = await UserManager.CreateAsync(user, model.Password);
So, kindly guide me how to create this code first database on my production server if it is providing SQL 2008.

Cannot Connect to Server - (with adding a new class and connecting to DB)

So I can actually connect to the server as it is localhosted. But when I created a class called Merchant and add the /Merchants to my local host address I get the above error, even though the server does just fine with all the other pages from the web site.
This is my first time messing with C# and Visual Studios, and I am following a tutorial but I got stuck here.
Using MS Visuals 2013, MCV 5.
Here is the Merchants function:
// GET: Merchants
public ActionResult Index()
{
return View(db.Merchants.ToList());
}
Here is the connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source= (LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20150610102919.mdf;Initial Catalog=aspnet-WebApplication1-20150610102919;Integrated Security=True"
providerName="System.Data.SqlClient" />
Here is the full error message:
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.)

Remote access using C# application to database created using SQL Server 2014 Management Studio

I have a database called Library created in SQL Server 2014 under my locally created server instance. I am using that database as the datasource in my windows form application. It is working perfectly when on my computer, but when I run it on other machines, it stops with the error
Unhandled exception occurred...
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 connection to SQL Server)
I have started all services from configuration manager and have enabled tcp/ip under protocols for MSSQLSERVER. Is there any way I can accomplish this, or do I have to shift to local db?
Make sure that your connection string includes your remote machine name as part of the "Data Source", so something like :
connectionString="Data Source=machinename\SQLExpress;Initial Catalog=mydbname;Integrated Security=True"
note that this connection string will target a db name "mydbname", under the machine machinename which has a SQL Express instance.
if that didn't work let me see your connection string.

SQL Server Connection using GPConnNet.dll for non sa user In microsoft dynamic gp

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;";

Categories