6

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:

picture

It works from the wizard, but not from code using TinyTDS!

zwiebl
  • 685
  • 2
  • 11
  • 24
  • Not familiar, but the host name could be just "qsss.gar.de" (also the port maybe 3000) – Ian Kenney Aug 03 '16 at 12:59
  • No, thats all fine, I am able to connect with exactly those parameters from the SQLPro wizard, but not from the application. – zwiebl Aug 03 '16 at 13:03
  • try changing the port to 3000 and removing the 3000 from the host as this has nothing to do with the host name. – engineersmnky Aug 03 '16 at 13:11
  • @engineersmnky I just tried, it is still the same situation. I can connect from SQLPro wizard with the parameters I provided, so those are most likely not the problem? – zwiebl Aug 03 '16 at 13:14
  • @zwiebl the `,3000` means use port 300 to connect right now based on you config you are trying to connect on 1433 which means the connection string would end up more like `qsss.gar.de\SQL2012,3000,1433` I bet this doesn't work in SQLPro. I think the second issue is the backslash when interpretted this will become `"qsss.gar.de\\SQL2012,3000"`. Maybe Try using dataserver option in place of host [TinyTDS Docs](https://github.com/rails-sqlserver/tiny_tds#tinytdsclient-usage) for more help. – engineersmnky Aug 03 '16 at 14:01
  • @engineersmnky I think you are right. I changed the port to 3000, and I removed the ,3000 from the host. Also I changed the "host" to "dataserver", and I got rid of that problem, but now I got a new problem... It now says: "Unable to connect: Adaptive Server is unavailable or does not exist (qsss.gar.de\SQL2012)" – zwiebl Aug 03 '16 at 14:29
  • @engineersmnky No, still the same. It now says "Unable to connect: Adaptive Server is unavailable or does not exist (qsss.gar.de\SQL2012,3000)". – zwiebl Aug 03 '16 at 14:48
  • @zwiebl this was my mistake in syntax see my answer and give that a try – engineersmnky Aug 03 '16 at 14:49
  • 1
    @engineersmnky I figured, if I change the Host to be just "qsss.gar.de", and not the "qsss.gar.de\SQL2012" that I am able to connect. So the problem is somewhere with parsing that "\". What interests me, do I even need to have this part "SQL2012" in order to work? Or will it work also if I leave it out? – zwiebl Aug 03 '16 at 15:14

3 Answers3

4

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.

2

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.

engineersmnky
  • 25,495
  • 2
  • 36
  • 52
  • I tried like you wrote, but it put me back to the initial error line: "Server name not found in configuration files" :( – zwiebl Aug 03 '16 at 14:53
  • What confuses me is that I get the following in the command line, as I try to reach the server: "Started GET "/" for ::1 at 2016-08-03 16:56:02 +0200. So the GET command is like for the empty IP address, it looks weird? – zwiebl Aug 03 '16 at 14:58
  • 1
    I figured, if I change the Host to be just "qsss.gar.de", and not the "qsss.gar.de\SQL2012" that I am able to connect. So the problem is somewhere with parsing that "\". What interests me, do I even need to have this part "SQL2012" in order to work? – zwiebl Aug 03 '16 at 15:14
  • @zwiebl if you have multiple instances of SQL running on that server then yes because that portion specifies the instance. – engineersmnky Aug 03 '16 at 15:38
0

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

Joshua Swain
  • 571
  • 2
  • 4
  • 22