Connecting to MySQL Cluster from WCF - wcf

I have configured server to use MySQL Cluster.
The Cluster works fine.
This is my server architecture:
Server 1: Cluster Manager: 10.176.133.219
Server 2: Data Node & Sql Node: 10.176.168.129
Server 3: Data Node & Sql Node: 10.176.137.66
My Question:
I have a WCF Service where I have put the connection string when I had 1 database (directly the server IP as database host).
How do I connect to the Cluster? How is the connection string written?
10x

connectionString="Data Source=10.176.168.129, 10.176.137.66;database=myDB;user id=myUsr;password=myPass"
the solution is putting the hostnames (address) as comma-separated.

Related

Cannot connect to SQL Server remotely from Management Studio

I have a SQL Server setup on one machine, where I have created a user and assigned a database to the user.
Now I want to access that server from client machine using management studio.
What I did:
I enabled remote access from Management Studio on the server machine from server properties and set authentication mode as "Windows auth and SQL Server auth"
I set TCP port as "1433" for IPAll in SQL Server Network Configuration and restarted SQL Server Services
I created an inbound rule in firewall settings to accept all connections on port "1433"
I added port forwarding in my router settings as follows: Router Port Forwarding
(That's my private IP address in destination address)
I types public IP (49.36.55.132\SQLEXPRESS) in client machine SQL Server Management Studio along with username and password with SQL Server authentication mode.
Getting this error on client machine:
Cannot connect to 49.36.55.132\SQLEXPRESS.
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: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)
Check out your port forwarding on your Server machine, you should add your port on your modem.
change your port, 1433 is default port.so you need to have Dynamic Port for you service.
First you have to completely disable firewall in server machine and check if client machine sees server. After that if it's ok, check connecting with sql server management studio from client and at last enable firewall with rules to check if error is from firewall port settings.

Issue connecting to SQL Server with new ASP.NET Core application

I've deployed a new .NET Core app to a production web server, and I'm having trouble connecting to a SQL Server database on another server. The web server currently has applications running on ASP.NET web forms and connecting to the database successfully.
The application is developed in ASP.NET Core 2.1. The database server is running SQL Server 2012 Express. The database is in a named instance called SQLEXPRESS which is using dynamic ports. I prefer not to change that since it's a production environment.
Here is the connection string that I'm using in my new app (potentially sensitive info omitted)
"ConnectionStrings": {
"NLogDb": "Server=<server>\\SQLEXPRESS;Database=<database>;User Id=<user>;Password=<password>;",
"DefaultConn": "Server=<server>\\SQLEXPRESS;Database=<database>;User Id=<user>;Password=<password>;"
},
I know that the servers are able to talk to one another because I currently have running applications talking back and forth. I also used portQry to test from the web server and got the following:
c:\PortQryV2>portqry.exe -n intinsap01 -p UDP -e 1434
Querying target system called:
<servername>
Attempting to resolve name to IP address...
Name resolved to 10.190.190.10
querying...
UDP port 1434 (ms-sql-m service): LISTENING or FILTERED
Sending SQL Server query to UDP port 1434...
Server's response:
ServerName <serverName>
InstanceName SQLEXPRESS
IsClustered No
Version 11.0.6020.0
tcp 65069
np \\<serverName>\pipe\MSSQL$SQLEXPRESS\sql\query
ServerName <serverName>
InstanceName RAPIDLOG
IsClustered No
Version 11.0.6020.0
tcp 1433
np \\<serverName>\pipe\MSSQL$RAPIDLOG\sql\query
Z ΒΆ
==== End of SQL Server query response ====
UDP port 1434 is LISTENING
The other application is using the following for a connection string:
<add name="<name>"
connectionString="Data Source=<server>\SQLEXPRESS;Initial Catalog=<database;Persist Security Info=True;User ID=<username>;Password=<password>"
providerName="System.Data.SqlClient" />
When the application tries to query the database I get the following error:
System.Data.SqlClient.SqlException (0x80131904): 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 suspect an issue with my connection string, but I'm not sure where to go with it.
Any help is appreciated.
I figured out what my problem was. I kept trying different variations in my connection string in my appsettings.json file. Eventually I noticed that there was an additional file named appsettings.production.json. The connection string in that was improperly formatted (not sure what happened there). The connection string that I originally posted was the right one.

SQL Server - Close external port and work as localhost when sql server and application are on the same server

My database and my web application are at the same server at the moment and I would like to access SQL Server as localhost and close the SQL Server port for remote connections.
This is my current connection string, how can I modify it so it will access the database from as localhost?
"ConnectionStrings": {
"DefaultConnection": "Server=tcp:152.242.211.112;Initial Catalog=testdb;User ID=usera;Password=********"
}
I tried:
server=(local)
tcp=127.0.0.1
Data Source=(local)
using Data Source=(local)\\SQLEXPRESS
I got this message:
A connection was successfully established with the server, but then an
error occurred during the login process. (provider: Shared Memory
Provider, error: 0 - No process is on the other end of the pipe.)
SQL Server uses the magic string (local) instead of localhost - this is because SQL Sever can use transports other than TCP/IP for connecting to the server instance (like Named Pipes and Shared Memory) whereas the hostname localhost is specific to TCP/IP.
So use Data Source=(local);Initial Catalog=... in your connecting string.

Unable to connect to SQL Server inside docker container

I have 2 docker containers (inside one of them I have an application, inside another SQL Server).
I tried to connect from the docker-container with application to the SQL Server database inside another container.
For this I did:
root#application:/# sqlcmd -S 172.17.0.1 -U sa -P test
After I got an issue:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
When I used this option inside docker-container with the SQL Server database without -S 172.17.0.1, it works fine.
Any ideas how to connect from container with application to the container with database via sqlcmd?
Update
I was mistaken, I used pass this command from docker-container with database.
Still have a problem with connection from app to the database
One way. The most "trust worthy" way IMHO.
You have to expose your sql-server as a SERVICE.
apiVersion: v1
kind: Service
metadata:
name: mssql-service-deployment
#namespace: mycustomnamespace
spec:
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
type: LoadBalancer
..
Then your connection string becomes:
jdbc:sqlserver://mssql-service-deployment.default.svc.cluster.local;DatabaseName=MyDB;"
where ".default." is the NAMESPACE of the exposed service.
Note the repeat (same string value) of "mssql-service-deployment"
This is documented here:
https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#namespaces-and-dns
When you create a Service, it creates a corresponding DNS entry. This
entry is of the form
..svc.cluster.local, which means that if
a container just uses , it will resolve to the service
which is local to a namespace. This is useful for using the same
configuration across multiple namespaces such as Development, Staging
and Production. If you want to reach across namespaces, you need to
use the fully qualified domain name (FQDN).

SQL Server Remote Access - Can't Connect

I've tried enabling TCP/IP - setting tcp port - restarting sql service - creating firewall inbound rule for the port - allowing remote connections on sql server - I'm able to ping - server name: tcp:, with correct credentials - server name: , and still not working.
What am I missing?
Error I'm getting:
Cannot connect to <server name>
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: TCP
Provider, error: 0 - The wait operation timed out.) (Microsoft SQL
Server, Error: 258)
If you are not setting the domain users then make sure you are using SQL Server authentication and either set up local user in the database or simply use the sa user (not recommended)
Because you are not specifying the SQL Server edition, please take a look this link for enabling remote access if you are using SQL Server 2005