tag:help.appveyor.com,2012-11-13:/discussions/problems/15028-using-sql-server-in-buildAppVeyor: Discussion 2018-09-09T21:00:34Ztag:help.appveyor.com,2012-11-13:Comment/456459602018-07-09T05:37:02Z2018-07-09T05:37:02ZUsing SQL Server in build<div><p>Is this a private repository?</p>
<p>You've declared an environment variable named <code>db_tst_connstr</code>, but can you explain or link to where in your project you make use of that variable/connection string?</p></div>Owen McDonnelltag:help.appveyor.com,2012-11-13:Comment/456459602018-07-09T14:03:48Z2018-07-09T14:03:48ZUsing SQL Server in build<div><p>Yes, it's a private repo.</p>
<p>I'm using it to poke the test app.config, which is working. The test is using the correct connection string, however when the tests start running, apparently it times out and show the error.</p></div>lporrastag:help.appveyor.com,2012-11-13:Comment/456459602018-07-09T19:34:00Z2018-07-09T19:34:00ZUsing SQL Server in build<div><p>Sorry, i still don't have a very clear picture of how this variable is being used.<br>
So you are trying to access this environment variable from the app.config file?</p></div>Owen McDonnelltag:help.appveyor.com,2012-11-13:Comment/456459602018-07-09T20:14:13Z2018-07-09T20:14:13ZUsing SQL Server in build<div><p>In the build script I write the value of the variable in the test's app.config file. In ConnectionStrings, so when the data/integration test run, it connects to appveyors db, instead of a local db.</p>
<p>The tests are using the correct ConnectionString as I am writing it in console:<br></p>
<pre>
<code>Running tests against Server=(local)\SQL2017;Database=technical_assessment_test;User ID=sa;Password=Password12!</code>
</pre>
The problem is when the test try to connects to the database, as the error is shown:<br>
<pre>
<code>System.Data.SqlClient.SqlException : 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)</code>
</pre></div>lporrastag:help.appveyor.com,2012-11-13:Comment/456459602018-07-10T01:02:08Z2018-07-10T01:02:08ZUsing SQL Server in build<div><p>Can you try adding the following section to your appveyor.yml file<br></p>
<pre>
<code>
before_test:
ps: |
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection "Server=(local)\SQL2017;Database=technical_assessment_test;User ID=sa;Password=Password12!";
$sqlConnection.Open();</code>
</pre>
and see if it throws an error.
<p>Also, try printing the content of the app.config file before and after your build script writes to it just to make sure its writing as expected.</p></div>Owen McDonnell