Having trouble with connecting to local database ,using my connection string - security

I have a windows service application that I am running. I can successfully connect to an external server and run the windows service, however when I try and connect to my local sql database the connection fails and I am not sure why.
This is the connection string that works to connect to external server
<add name="MarketingDBEntitiesModel" connectionString="Data Source=184.17.0.38;Initial catalog=MarketingDB;User ID=John;Password=JohnDoe#4321;Connection Timeout=0" providerName="System.Data.SqlClient" />
and this is the connection string that is failing to connect to local instance
<add name="MarketingDBEntitiesModel" connectionString="Data source=local;Initial catalog=MarketingDB;integrated security=True;Connection Timeout=0" providerName="System.Data.EntityClient" />

Related

Azure hybrid connection Manager does not work

Requirement
I have an On-Premise SQL Server and an Azure webApp Service that needs to talk each other. I installed Hybrid Connection Manager on another computer which is in the same LAN as the SQL server. Let's refer this computer as the Connection PC.
The working part
Installation and configuration was straight forward, status of the hybrid connection showing as connected.
Tested the WebApp on localhost, it worked fine. Which means nothing wrong with the asp.net code
SSMS on the connection PC can access and query SQL DB
I installed a test SQL DB on the connection PC itself and use the WebApp to talk to the test DB instead, It worked fine.
The Problem
After tested ok on localhost, I published ASP.Net WebApp to Azure, it gave 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
troubleshoot attempt
Does that mean Hybrid Connection manager has to be installed on the same computer that runs SQL Server?
I did attempt to install HCM on the SQL Server, but it says it cannot work with Win2008R2. The connection PC has win2012 on it. So it can have HCM.
I just do not have time to migrate the SQL Server to another server. So I hope HCM does not have to be on SQL server.
Connection String
In my webapp, the connection string is as follows.
connectionString="metadata=res:///ScaleDataModel.csdl|res:///ScaleDataModel.ssdl|res://*/ScaleDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=WIN2008R2\DataPlus;initial catalog=DataPlus;persist security info=True;user id=test;password=testpass;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"
Hybrid Connection communicates via TCP ports thus you need to specify the listening static port in your connection string like:
Data source=ServerName:Port;
Also here is an actually detailed article about the all problems you may encounter while working with Hybrid Connections.
Hope this helped you.
Since you have a hybrid connection, your connection string should have the endpoint name of your hybrid connection as the data source. Try replacing it.

Hybrid Connections in Azure

I have created a sample ASP.NET MVC app (the standard one you get in Visual Studio). I have deployed this to Azure and it works fine. I have SQL Server 2016 running locally (on premise) on my machine and the cloud app uses this database. I have created a hybrid connection and everything is connected as it should be. But when I run the app its not connecting to the database for some reason. The connection string works fine locally:
<add name="DefaultConnection" connectionString="Server=MyPC-QQ5, 1433;Initial Catalog=myDataBase;User Id=sa;Password=thePassword!;" providerName="System.Data.SqlClient" />
Is anyone else experiencing this problem.

Cannot connect to named shared LocalDB instance

I spent hours on this with no success. Any help appriciated:
I create LocalDB instance
sqllocaldb create test
i start that instance
sqllocaldb start test
i share that instance with same user account that owns the original instance
sqllocaldb share "domain\user" test testShared
Both instances are in "running" state.
I launch MS SQL Management studio and try to connect to instances. Results:
I'm able to connect to both instances using named pipes - OK.
I'm able to connect to (localdb)\test - OK.
I'm not able to connect to (localdb)\.\testShared - NOT OK.
Error message:
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) (Microsoft SQL Server, Error: 2)
Any ideas? I tried that on 4 different computers. It works correctly on two of them. 3 of coputers are connected to domain (so it has probably nothing to do with domain environment).
In SQL Configuration Manager - all protocols are enabled.
What I need to achieve - share the LocalDB instance with IIS APPPOOL\ASP.NET v4.0 account according to this.
Based on the exact steps, as you described them, all you need to do is to restart your instance. It is required after you share it, so that it listens on the public pipe with the well known name that was assigned to it by the sharing process.
you need to enable setProfileEnvironment. This requires editing
applicationHost.config file which is usually located in
C:\Windows\System32\inetsrv\config. Following the instructions from KB
2547655 we should enable both flags for Application Pool ASP.NET v4.0,
like this:
http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-1-user-profile.aspx
<applicationPools>
<add name="DefaultAppPool">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
<add name="ASP.NET v4.0" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>

Entity Framework 5 and Amazon RDS - "The underlying provider failed on Open."

I have a C# / Entity Framework web application runs fine against a local SQL 2012 db. I copied the db out to a new RDS instance, and can access the db via Visual Studio and SQL Server Management Studio.
I hav a unit test which authenticates the user and then attempts inserts a record in a table using an Entity Framework call -- dataContext.SaveChanges().
I get the following error:
{"The underlying provider failed on Open."}
{"No such host is known"}
{"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 - No such host is known.)"}
I've poked around the web for answer all day, and so far no success with any of the suggestions I found:
Port 1433 is open I can access the entry point via Telnet
My IP address is covered by the CIDR/IP range for the default security
group.
The error occurs as soon as I attempt to open the connection
on the datacontext.
The db server is configured to accept remote
connections.
The db server is configured to use mixed authentication
(both Windows and SQL Server).
Entity Framework Connection String
connectionString = "metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MyAwsEntryPoint;Initial Catalog=MyDb;User ID=MyUser;Password=MyPassword;Persist Security Info=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"
Standard Db Connection String
connectionString = "Data Source=MyAwsEntryPoint,1433;Initial Catalog=MyDb;User ID=MyUser;Password=MyPassword;Persist Security Info=True;Application Name=MyAppName;"
The problem was in the connection string. Specifically, I had "Application Name" and "App" properties in there. Once I removed those, it worked.
BAD:
<add name="MyDbEntities" connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MyDbServer;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyDb;Password=MyPassword;Application Name=MyDb.API.Models;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
GOOD:
<add name="MyDbEntities" connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MyDbServer;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyDb;Password=MyPassword;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />

Access denied creating App_Data subdirectory

I've created a user from the ASP.NET Configuration
I'm using sql server but I haven't created any database for membership.
I did add this to the config file:
<authentication mode="Forms">
<forms loginUrl="Login.aspx"></forms>
</authentication>
<authorization>
<allow users="admin" />
<deny users="?" />
</authorization>
where admin is the user I did creat.
and it works very well localy.
after I have uploded my website I got an error that I have to create an App_Data folder with write permission and add it to my application folder, now I get this :
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)
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.
The above error message that you are getting will only occur on a remote call. It may work locally fine. This is due to the fact that the remote connections are not enabled on the SQL Server surface Area configuration. To accomplish this, please follow below steps:
Make sure your database engine is configured to accept remote connections:
• Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
• Click on Surface Area Configuration for Services and Connections
• Select the instance that is having a problem > Database Engine > Remote Connections
• Enable local and remote connections
• Restart instance
Alternatively, if you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your ASweb P.NET application
• Usually the format needed to specify the database server is machinename\instancename
• Check your connection string as well
**
**

Resources