Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyTDS: Server name not found in configuration files

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!

like image 496
zwiebl Avatar asked Aug 03 '16 12:08

zwiebl


2 Answers

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.

like image 178
Noelio Alves Avatar answered Nov 15 '22 04:11

Noelio Alves


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.

like image 2
engineersmnky Avatar answered Nov 15 '22 06:11

engineersmnky