Roles based authorization breaking my app - asp.net-mvc-5

The registration works fine, user is created, and the role the new user chooses is applied fine. On some controllers I restrict access with [Authorize] and this works good with the user being redirected to the login. The problem arises when I want to authorize by roles. When I change
[Authorize]
to
[Authorize(Roles = "Sales")]
the app hangs before the browser reports the 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)
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
This only happens when I add the role condition. The Default connection in the Web.Config points to the SQL Server database I am using. For some reason, the condition of allowing only certain roles makes it want to start creating a database with SQLExpress
Why is this happening and how do I stop it?

Related

Connect Azure App Service and Azure SQL VM

I have a setup where the connection string of my .NET application is configured at the app service level and the database used in it is present in an Azure SQL VM
I see the following error, while accessing my Web APIs in the app service
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 - Access is denied.
However, I’m able to connect to the database directly on my local system using SSMS with my organisation’s VPN
I’m struggling to find the right resource, appreciate if you someone can help me with steps to fix it
i just have the beginner level knowledge on Azure platform
I tried to reproduce the same in my environment I got the same error like below.
To resolve this issue i have removed private access and tried and then added new private access its work successfully.
Check the public access in selected network with firewall rule and allow exception as below.
And, when I remove this private endpoint and try to add new private access i can able to connect with my sql server.
Check this connectivity as below.
My azuresql,database server connected successfully.
Note: This error may occur in multiple ways if are not enable sql services and in tcp/Ip If any of the protocols are disabled or if Remote Connection Permission is disable error may occur for this please refer the below documents.
Reference:
Microsoft SQL Server Error 2 Cannot Connect to Local: How to Solve? (systoolsgroup.com)
Resolving could not open a connection to SQL Server errors (mssqltips.com)

How to migrate a dockerized SQL Server database that uses a custom port to Azure SQL

I am hosting a bunch of micro-services and bot apps using Docker, and Azure virtual machines. There´s also a dockerized SQL Server 2017 instance in the stack, which I would like to migrate to Azure SQL. I am out of luck when trying to configure the source database in an Azure Database Migration project...
I tried to specify the service endpoint including the exposed port (since the dockerized SQL Server container´s public port is not 1433). I can connect to the SQL Server instance using SSMS from my workstation with no error, so connectivity is not the problem at all; does the Azure Database Migration require port 1433, or if not, how can I correctly specify a different port?
These are the error details I got from source details configuration in the Azure portal:
Error Type
Failed to connect, please check error details
Error Detail
Collector 'Microsoft.SqlServer.Advisor.SqlQueries.Contracts.Models.IQueryServerProperties' failed to collect data. 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)
The parameter is incorrect
The source database configuration wizard is not very clear about the format of the remote server´s DNS name. Just specifying the fully qualified DNS name and port is not enough; it must contain the server´s instance name as well.
Wrong:
<DNS-name>,<port>
Correct:
<DNS-name>\<INSTANCENAME>,<port>

Cant connect to Azure DB from Azure web application

I am trying to set up a new azure website. I have done this before and everything just worked, this time I'm having real trouble getting the database set up.
I setup both site and database in the deploy wizard, and have a connection string named the same as on my local box. The error I'm getting is below:
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)
If i copy paste the connection string from azure to my local box (and add my local ip to the whitelist for SqlAzure) then it works fine locally (which is why I'm a little stumped)
The only thing that that I have noticed is that if I download the web.config for the site as configured in azure there are no connection strings. I imagine that this is because they are doing some clever security thing.
Any idea what I can even try next to diagnose this?

SqlException & Timer Job

I found the below ULS Log entries, Timer job (OWSTimer.EXE) is causing this however would like to know the name of the Timer-job, how can i achieve this? (without enabling verbose logging)
System.Data.SqlClient.SqlException: 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.
SqlError: '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.)' Source: '.Net SqlClient Data
Provider' Number: 258 State: 0 Class:
20 Procedure: '' LineNumber: 0 Server:
''
You could try using a tool like wireshark to see what kind of network traffic is being generated and under which account a request and to which SQL box is being made. I suspect this error is triggered one of the following ways (first 2 unlikely ones, then the likely problem):
Not likely: a security issue, sql is inaccessible to the account the call is made under, maybe originating from a timerjob that uses a (non sharepoint) database of it's own.
Not likely: a (non sharepoint) database used by a timerjob doesn't exist anymore, or the sql box it was running on is unreachable.
Very likely, a webapp is running using either the local service or the network service account (or any other local user). Code in timerjobs etc. bound to that webapp might use that account. If it is a local account, it won't have access to a database on another machine if you haven't granted access to that account on the sql machine. And granting a local account from machine A access to machine is not something you would normally do (I hope).

Ingres connection on an IIS deployed site

I have a .net 2.0 app being hosted on IIS, that connects to a Ingres DB. The connection uses iBatis with an ODBC driver to connect to an ingres database being protected behind an installation password.
For some reason, when I'm debugging my code, everything runs fine. It establishes the connection without any problems. However, when I try to host the site on my local IIS, ingres comes back with this error
ERROR [5000H] [CA][Ingres ODBC Driver][Ingres]User authorization check failed.
Your user identifier was not known to this installation.
Contact your system manager for further assistance.
ERROR [08S01] [CA][Ingres ODBC Driver][Ingres]The connection to the server has been aborted.
I'm wondering why the installation password would work fine against my debug session, and refuse to connect behind IIS? Does IIS use a different 'name' that isn't my computer name to establish a connection with the installation password?
The connection is being rejected because the target server is not aware of the user trying to connect or that user has not been added. Check to see if the process owner of your local IIS instance is a valid ingres user. IIRC the account name is normally something like IUSR_MACHINENAME, where MACHINENAME is the hostname of your IIS box. Add the user account using the following SQL on the server:
echo "create user IUSR_MACHINENAME\g" | sql iidbdb

Resources