Connect to SQL server from batch file

Susja 716 Reputation points
2020-08-31T15:35:53.83+00:00

Hello,
I have a batch file that I use to start application from Win 7 client. It will connect to remote SQL Server and start application.
It looks like this
pushd \<server>\MITRE\SoftwareReleases\v23-lfhm
cmd /c start LaminarFlowHoodModule.exe
Note: at the location I have configuration file LaminarFlowHoodModule.config with the name of database, creds and etc. It does not state which driver to use. I assume that it is coded inside LaminarFlowHoodModule.exe
This is the section from LaminarFlowHoodModule.config

<!-- Database settings -->
    <add key="DataSource" value="server" />
    <add key="InitialCatalog" value="database" />
    <add key="TrustedConnection" value="false" />
    <!-- Username/password required if TrustedConnection is false -->
    <add key="UserName" value="user" />
    <add key="Password" value="password/>

Recently it stopped working and it failed to connect to database.
I installed latest SQL Server Native client driver and was able to create ODBC connection e.g. 'connection1' and then connect to database with no problem.
Hence, my question:
Could I create another batch file of modify existing one in order to force LaminarFlowHoodModule.exe to use ''connection1' ?
Thanks

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,999 questions
{count} votes

8 answers

Sort by: Most helpful
  1. Tom Phillips 17,741 Reputation points
    2020-08-31T18:31:10.233+00:00

    Without knowing the code and/or having an actual error message, it is impossible to guess. It is possible the code does not even use that config file.

    The most common reason it would have stopped working all of a sudden is a firewall or router setting has changed.

    2 people found this answer helpful.
    0 comments No comments

  2. Dan Guzman 9,236 Reputation points
    2020-09-05T13:46:17.857+00:00

    I just realized that the issue I'm having with connection is caused by the change our IT did in Group policy for Win 7 for security reason.
    Based on that I assume that all my attempts to fix it using some workarounds would be useless.
    I am still confused why connection using ODBC works fine … How this type of connection could 'disregard' Group policy.
    Anyway … do you think I should stop these efforts and simply replace Win7 for Win 10?

    Yes, I recommend moving to a supported OS as the best solution. My guess is that the group policy change is related to TLS 1.2 so the combination of an older .NET version and OS version can't negotiate the needed TLS level. The newer ODBC driver with the proper TLS support doesn't experience the issue.

    1 person found this answer helpful.
    0 comments No comments

  3. Susja 716 Reputation points
    2020-08-31T18:27:46.02+00:00

    Well Dan,
    Sounds very reasonable to me what you suggested.
    DB admin checked and did not find any clue in the server log.
    You suggestion to use https://support.microsoft.com/en-us/help/4557473/errors-when-applications-try-to-connect-to-sql-server-in-windows did not make a difference in my case.
    Since I don't have access to app sources I could only assume that it's hard-coded or use 'default' driver or etc.
    Anyway ... my point was/is to find workaround without changing the app code itself.
    Appreciate your help

    0 comments No comments

  4. m 4,271 Reputation points
    2020-09-01T06:26:35.043+00:00

    Hi @Susja ,

    Do you get one error message? And what is it?
    And verify whether there is error information in your error log.By default, the error log is located at Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG and ERRORLOG.n files.

    BR,
    Mia

    0 comments No comments

  5. Susja 716 Reputation points
    2020-09-01T10:35:35.093+00:00

    Hi @Yuximiao-MSFT
    The only error message that I’ve got on client side is 'Unable connect to database'. This type of error is 'expected' and defined in configuration file when client failed to connect to database.
    I requested db administrator to check logs on database server. He checked and reported that nothing related to the issue was found.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.