Reputation: 725
I keep seeing this error, and I am unable to connect to the database on the remote server.
I am given a connection string to the database, that looks like the following:
data source=qsss.gar.de\SQL2012,3000;initial catalog=City;persist security info=True;user id=user_me;password=user_me##2009;
Now, I have created a database.yml
file based on that connection string, like the following:
development:
adapter: 'sqlserver'
host: 'qsss.gar.de\SQL2012,3000'
port: 1433
database: 'City'
username: 'user_me'
password: 'user_me##2009'
And as I try and run the server, it always hits me with the Server name not found in configuration files error.
opts[:port] ||= 1433
opts[:dataserver] = "#{opts[:host]}:#{opts[:port]}" if opts[:dataserver].to_s.empty?
connect(opts) // ERROR AT THIS LINE
end
def tds_73?
Please try and help me figure what is the problem with this?
UPDATE:
I can connect to the server using SQLPro for MSSQL
wizard, with exactly the same connection parameters:
It works from the wizard, but not from code using TinyTDS!
Upvotes: 8
Views: 10384
Reputation: 690
My problem was the version of the database container I was connecting to. I was connecting to a SQL Server db via docker. When things weren't working, I was using the container 2019-latest
. Things started working when I switched to 2019-CU6-ubuntu-16.04
Upvotes: 0
Reputation: 41
I was having the same problem and I was able to resolve it by changing the "host" parameter to "dataserver" in the config.yml file.
Also check if the server running the application is able to resolve the DNS name of the database server if it does not put the IP of the server.
I also use Microsoft SQL database and can only resolve the "TinyTds :: Error: Server name not found in configuration files" error after changing the above file.
Upvotes: 4
Reputation: 29488
Please try this
development:
adapter: 'sqlserver'
dataserver: 'qsss.gar.de\SQL2012:3000'
database: 'City'
username: 'user_me'
password: 'user_me##2009'
Your current configuration is suffering from 2 things
First you are specifying a port and including it in the host value so this will actually look like qsss.gar.de\SQL2012,3000:1433
Second when the host is interpreted the backslash will get doubled up e.g. qsss.gar.de\\SQL2012,3000:1433
The dataserver
option should resolve this as TinyTDS says this option will support the backslash and the port in hostname:port
format. I have not tested this but according to the documentation it should be a sufficient solution.
Upvotes: 3