TNS oracle connection failed from MVC3 site using ASP.NET Membership provider - asp.net-mvc-3

We have an MVC3 site that uses the ASP.NET Membership Provider with Forms Authentication to let users onto the site. We have an Oracle database behind it.
It all works in house on development machines, test machines and deployment machines.
But at a client - they are getting the error "ORA-12154: TNS:could not resolve the connect identifier specified".
We thought this would be a simple case of a wrong config entry but all seems correct. They've also run a tnsping to the same TNS alias and it works. A connection via SQL*Plus also works. We've even got them to download a .NET connection string tester application and that connects ok using exactly the same connection string as the MVC3 site web.config has. It's only the website that comes back with this error. (note: all the tests were done from the same machine as the website is on)
Has anyone seen this before and provide some guidance on how to solve?
Thanks

The likely cause for this, from experience, is that the account under which the application is running is unable to read/access the TNSNAMES.ORA file, either due to file/folder permissions or network access permissions.

Related

How can I run my project on client pc without installing SQL server on client pc

I have developed a c# windows application which uses SQL server 2012 database in Visual Studio 2015 which is running well on my pc.
I am to install this application on a number of computers without SQL server installed on it, but when I run the application, its gives me database connection error.
My question is, how can I create the setup file to be able to run the app on those clients pc without installing SQL server on all those computers. Please I need your help.
Thank you.
Am Emmanuel.
Use an Azure database and have the clients connect to that.
Have a look at https://azure.microsoft.com/en-us/services/sql-database/
Alter your application connection string and make sure you keep the connection string secret.
Server=tcp:myserver.database.windows.net,1433;Database=myDataBase;User ID=mylogin#myserver;Password=myPassword;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True;
An important fact is that the clients need to allow communication via port 1433.
If this is not an option create an API application and query the database via that.
If you need a private database per client you can use a database file and connect to the file
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15
Update based on reply
You can create a pop-up on the application allowing the users to add valid settings and credentials when your appsettings.json is blank or "a test connect" to the database fails.

SQL Server 2017 Connections working in ASP.NET C# Web projects, but not in Windows projects, in Visual Studio 2019

Using the basic SqlConnection code below, I have discovered that, at my workstation, I am unable to connect to our Sql Server 2017 deployment via ASP.NET C# code in any given type of Windows-based project, such as Winforms (.NET Framework or Core) or Console apps. However, this code will run without incident in any Web-based project, such as Web Forms or MVC, either using .NET Framework or Core.
protected void testConnection()
{
string con = "Server=MySqlServer;database=MyDatabase;Integrated Security=true";
using (SqlConnection cnn = new SqlConnection(con))
{
cnn.Open();
cnn.Close();
}
}
In a web project, this code runs. In a Windows project, I get this error:
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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
In investigating this problem, I have tried the following:
Explicitly declaring the domain on which my SQL server is found (eg. MySqlServer.domain.com). No good.
Explicitly declaring the SQL Server port number, according to the example shown on connectionstrings.com (eg. MySqlServer, 1433). We do use the standard port number, for the record. No good.
Changing the protection level of the test method (protected/private/public). No good.
Connecting to the SQL Server in PowerShell. This connection worked.
Pinging in the SQL Server in a command prompt. The server responded in 1ms consistently.
I have asked other users on this network to test this code in a Winforms project on their workstations. No one is able to reproduce my issue.
Consulted my sysadmin. He is so far not able to find any reason why I should be having this issue.
The only difference I have noticed in all of this is that, when I declare the port number, the Inner Exception returned with the error reads "Win32Exception: A non-recoverable error occurred during a database lookup". Otherwise, it simply reads "Access is Denied."
All of this tells me that the issue is obviously something peculiar to my workstation, but I have no idea what, apart from some firewall or other local security setting that the sysadmin neglected to check. Has anyone encountered this problem?
My VS 2019 installation is only one revision out of date as of this writing, 16.8.3 as opposed to 16.8.4. I am able to connect to and run TSQL code on any database I care to via SSMS. We connect using Windows Authentication. According to the results of "select ##version", our version of SQL Server is 2017, 14.0.3356.20 (x64).
Any insight is appreciated.
We fixed it by forcing Named Pipes to be enabled in SQL Server, as opposed to using the default setting.

Visual Studio webdeploy fail even when connection is validated?

I am trying to deploy my webapp VS2015 RC1 DNX 451. Even when I validate connection and run publish I get error
Severity Code Description Project File
Error Error Code: ERROR_USER_UNAUTHORIZED
Error More Information: Connected to the remote computer ("crocus.arvixe.com") using the Web Management Service, but could not authorize. Make sure that you are using the correct user name and password, that the site you are connecting to exists, and that the credentials represent a user who has permissions to access the site. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.
Error Error: The remote server returned an error: (401) Unauthorized.
Googling the issue and even trying to view host forum just says make sure username and password is correct. I am getting nowhere trying various settings. Any ideas how to debug the issue?
I am using Arvixe.com as host.
You should contact Arvixe.com. They likely have some odd configuration on their servers but I would suspect they can help you resolve the issue.
Arvixe does not support Web Deploy anymore. Once they move you to their new servers Web Deploy won't be available to you. In Visual Studio you can set up a Publish with FTP instead of Web Deploy. If you're used to Web Deploy publishing your database changes, then you'll need to do those yourself with SQL scripts. Entity Frameworks has an option to produce a SQL script for a migration, so you can use that to publish your EF database changes.

IIS to SQL Server Error 26, Same connection string works outside of IIS but not from within

I have gone through every checklist I could find for configuring SQL Server I could find. I get the same issue on Windows Server 2008 and Windows 7 Pro. First the environment:
SQL Server Express 2012 --installed as main instance (i.e. no named instances)
IP access turned on
Firewall exception for SQLServer
SQL Server user for application access
Windows Server 2008 service pack 2 (also tested with Windows 7 service pack 1)
IIS 7 (also tested with 7.5 with the same results)
.NET 4.0
Our own database code integrated in a .NET MVC 3 application
We have a tool we developed to import data from the old Ruby on Rails app into the new ASP.NET MVC 3 app. The tool can connect to the database using the user account we created, and that's how I discovered some permissions issues for access to stored procedures. This is the tool we are using to verify the connection works.
Data Source=SERVER_IP,1433;Network Library=DBMSSOCN;Database=MYDB;User ID=webuser;Password=webpassword;multipleactiveresultsets=true;
We are using a straight IP address, but to protect our infrastructure I substituted the IP, username, and password. But this is the structure of the connection string we are using. Following the checklists, I was able to connect from another machine on our network using the import tool to the database and import data. I was also able to import data from the same machine that IIS is installed on.
The same connection string provides the dreaded Error 26 "can't find the database server" message on both Windows Server 2008 and Windows 7 Pro:
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 exhausted every resource I can find, and can't seem to get any closer to an answer. I'm not trying to mount file based database, IIS has read/write access to the web application in any case.
I've ruled out the firewall as a cause for the issue. I've tried the settings with the firewall on and completely turned off. There has to be some other permissions level problem that's happening. Problem is I have no idea what permissions level things I have to check.
After opening a ticket with Microsoft, it turns out I was my own worst enemy. The model classes were set up in their own DLL so I could use them for data migration and other supporting tools for the website.
The DLL was looking in the assembly config for the connection string, and if it wasn't found it would use a reasonable default. Problem is the web application never overrode the location from the Web.config file.
The application couldn't find it because I didn't install the database with the default settings.

Can't Connect to Database when Web Application is deployed to IIS

i have developed an application and it is working fine but when ever i create a virtual directory for it in IIS and run the application i am getting connection failure exception and named pipes exception.
thanks!
It looks like you having some issue with the database connection from your application. Can you post your code and the exact nature of the error.
Without any code or details of the language it is hard to guess what the issue can be however a common one that occurs with asp.net could be your database connection string. Are you using a SQl Server / Sql Server Express database with your application? You need to check that the connection string.
The problem is the Integrated Security=True setting in your connection string. IIS uses the ASPNET windows login which will be different to the Windows login used when running from VS. You've got a few options:
Grant the ASPNET user the required access rights on your database
Use Sql Server authentication: Set up a user on the database as a sql login and pass this username / password in on the connection string and set Integrated Security=False
Change the identity IIS runs under to one that has access to the DB.
There may be other options also however I think these are most common. Which to choose depends on the architecture you are deploying to, personally I almost always go for Sql Server Authentication using a username and password. The web.config can be encrypted for further security if required.

Resources