Connect to remote sql server via alias - entity-framework

My connection string is working when I am connecting via IP adresss
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=ALIAS_SERVERNAME;Initial Catalog=DATABASE_NAME;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="DefaultContainer" connectionString="metadata=res://*/Models.Db.ModelName.csdl|res://*/Models.Db.ModelName.ssdl|res://*/Models.Db.ModelDb.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.0.61;initial catalog=DATABASE_NAME;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I have created Alias on remote server, like I did it localy (same ports and names) ,but it doesnt working. And when I put IP addres in connection string, like the one I have posted it is working.
Can someone pleas give me some instructions on how to troubleshot problem.
Error I am getting when I try to connect via Alias, and via IP it is working. Btw can connect localy via Alias.
(EntityException): The underlying provider failed on Open.

So, your DB server is aware of its alias name, but your application server is not. You have to create alias on application server.
You can do that with
cliconfg.exe
(Start > Run > cliconfg > Click "OK")
And than set your protocol, and port same as on DB server

You might need to add SQL Server name i.e. SQLEXPRESS, etc. at the end of your alias as shown below:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=ALIAS_SERVERNAME\SQLEXPRESS;
Initial Catalog=DATABASE_NAME;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
If you do not use default name for MSSQL Server then you need to change with what you used as name of it. You can check it on the Server Name field of the Connect dialog of SQL Server Management Studio as shown below.
Update: Here is the DataLink properties dialog shown below:
If it does not solved the problem, have a look at The underlying provider failed on open. Hope this helps...

Related

ASP.NET Core 3.1 - "site can’t provide a secure connection" when setting application url using .UseUrls()

I'm running the app using "dotnet run". If I don't set the url programmatically using .UseUrls() then it picks it up from launchSettings.json and all good. However if I set THE SAME url using .UseUrls() I get the message below on the brower.
There are no errors from the code i.e. both cases report " Now listening on: http://localhost:6001". Any ideas?
Remove Strict-Transport-Security from your Web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security"
value="max-age=16070400; includeSubDomains" />
</customHeaders>
</httpProtocol>
</system.webServer>
My mistake - launchSettings.json was using https://localhost:6001 and the code was using http://localhost:6001. Doh!

How to add a domain name to an existing WCF REST web service?

I have an existing WCF REST service running on an Azure Windows Server 2012 using IIS8. Let say 1x.2x.3x.4x:7777/InvService.svc/RESTquery is how my users currently use the service.
I am wanting to replace the IP address with a hostname, say www.testDomain.com so the user will can then use www.testDomain.com:7777/InvService.svc/RESTquery.
After obtaining the domain name from GoDaddy, assigning IP 1x.2x.3x.4x, and testing it (my default site on the server comes up, hence why I am using port 7777). When I try www.testDomain.com:7777/InvService.svc/RESTquery I get a "Connection Timed Out" error.
I believe I am needing to add or change something inside my Web.config file but cannot seem to find the right answer. Here is what my current unsuccessful Web.config file looks like.
<services>
<service name="WCFInventoryService.InvService">
<endpoint address="RESTquery" behaviorConfiguration="restPoxBehavior"
binding="webHttpBinding" contract="WCFInventoryService.IInvService" />
<identity>
<dns value="www.testDomain.com" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://www.testDomain.com/"/>
</baseAddresses>
</host>
</service>
</services>
What am I doing wrong? or should try?
I solved my problem. The problem was how the domain was set up in GoDaddy. In the GoDaddy account, the domain was set up to forward to the IP address and not to point to. Once I removed the forwarding record and changed the A record to point to the IP address in the GoDaddy account, the WCF service was accessible by using www.testDomain.com:7777/InvService.svc/RESTquery

NWebsec's "A potentially dangerous redirect was detected" with Facebook logon

I have read through NWebSec's documentation to try and resolve the problem.
Set the web.config to
<nwebsec>
<httpHeaderSecurityModule
xsi:noNamespaceSchemaLocation="NWebsecConfig/HttpHeaderSecurityModuleConfig.xsd"
xmlns="http://nwebsec.com/HttpHeaderSecurityModuleConfig.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<redirectValidation enabled="false">
<allowSameHostRedirectsToHttps enabled="false"/>
<add allowedDestination="https://www.facebook.com/"/>
<add allowedDestination="http://www.nwebsec.com/"/>
<add allowedDestination="https://www.google.com/accounts/"/>
</redirectValidation>
<securityHttpHeaders>
<strict-Transport-Security max-age="365" includeSubdomains="true" httpsOnly="false" preload="true" />
</securityHttpHeaders>
</httpHeaderSecurityModule>
but I am still getting
A potentially dangerous redirect was detected. Add the destination to the whitelist in configuration if the redirect was intended. Offending redirect: https://www.facebook.com/dialog/oauth?response_type=code&
This came up in google before the answer, which is here: https://docs.nwebsec.com/en/latest/nwebsec/Redirect-validation.html
In summary you have to whitelist the URL which your login service refers to, like this:
app.UseRedirectValidation(opts =>
{
opts.AllowedDestinations( "https://www.facebook.com/dialog/oauth");
opts.AllowedDestinations("https://login.microsoftonline.com"); // Tested
});

Login failed for user Test_web'. code first

heelo this is my connection string
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True" providerName="System.Data.SqlClient;Password=;User ID=;"/>
</connectionStrings>
<appSettings>
and this is my error please help me
Cannot open database "DataLayer.Context.test" requested by the login. The login failed.
Login failed for user 'test\test_web'.
You have specified the "DefaultConnection" as name of the connection string here. so your context class should have the same name. (it's the default convention in ef code-first)

Unable to connect to ADAM with Windows domain\username

I'm having some difficulty connecting to an ADAM instance from my Commerce Server 2007 ASP .NET solution, and I believe it relates to my config file somehow. The short version is that I can connect to ADAM through ADAM-ADSIEdit with my current username/password, but when I put this in my web.config i get "Parser Error Message: Logon failure: unknown user name or bad password."
<connectionStrings>
<add name="LDAPConnection" connectionString="LDAP://<domain/>:389/<Partition DN>" />
</connectionStrings>
<membership defaultProvider="MembershipADAMProvider">
<providers>
<add name="MembershipADAMProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="LDAPConnection"
connectionProtection="None"
connectionUsername="<domain>\<username>"
connectionPassword="<password>"/>
</providers>
</membership>
I've tried a bunch of things to fix this and haven't come up with any kind of reasonable solution. I started with just the connection String and no username or password. I got an error saying that I could not make a secure connection. that's when I added the connectionProtection="None" line. Then it said I could not use default credentials without a secure connection, so I added the Username and Password fields. When I created the ADAM instance, I used the current Windows login credentials. I've tried to use my windows login credentials here in web.config, and I've tried with various domain names, pretty much anything I could think of. I'm totally lost why I cant bind with ldp and I can connect in ASIEdit with these domain\username and password but can't from my CommerceServer ASP .NET application...Is there some other step I'm missing?
Thanks,
John
You should follow the information here, there is a lot of good stuff about secure connections and how to disable them within your ADAM instance for development purposes.