Using SqlServer when running auto-test

Bjarne's Avatar

Bjarne

27 Feb, 2015 12:38 PM

I would like to use Sql Server when running auto-test.

I have added the SqlServer2014Express service on the environments tab.
I'm using this connection string "Server=(local)\SQL2014;Database=TestDb;User ID=sa;Password=Password12!"
I'm using the EntityFramework database initialiser "DropCreateDatabaseAlways".

I get this error:
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)

Any thoughts?

Bjarne

  1. Support Staff 1 Posted by Feodor Fitsner on 27 Feb, 2015 02:28 PM

    Feodor Fitsner's Avatar

    Will take a look.

    -Feodor

  2. Support Staff 2 Posted by Feodor Fitsner on 27 Feb, 2015 03:08 PM

    Feodor Fitsner's Avatar

    Do you see these two messages (or at least the first one) in a build log?

    Starting SQL Server 2014 Express
    Waiting for service 'SQL Server (SQL2014) (MSSQL$SQL2014)' to start...
    
  3. 3 Posted by Bjarne Riis on 27 Feb, 2015 04:27 PM

    Bjarne Riis's Avatar

    Hi Feodor

    Thank you taking a look :-)

    Yes, I see both those messages.

    Regards
    Bjarne

  4. Support Staff 4 Posted by Feodor Fitsner on 27 Feb, 2015 05:35 PM

    Feodor Fitsner's Avatar

    Are you running on Pro or Azure environment?

    I did some tests with SQL 2014 and it worked just fine on Pro workers.

    Test #1 - deploying DACPAC to a new SQL Server database with msdeploy and then checking database contents with SqlCommand:

    Test #2 - more extreme - enabling TCP/IP on SQL Server 2014 instance, setting its alias to (local) and then accessing it with sqlcmd:

  5. 5 Posted by Bjarne Riis on 02 Mar, 2015 11:57 AM

    Bjarne Riis's Avatar

    Hi Feodor

    I don’t know if it’s Pro or Azure. The account I’m working on is named ‘LauritzITDevelopment’.

    I have found some new information :-)

    It appears that the Sql Server works just fine. The real problem seems to be, that when I run the tests, then xunit.console doesn’t load the config file of my test project.
    Instead it has loaded its own config file located at c:\Tools\xUnit\xunit.console.clr4.x86.exe.Config.

    Feel free to take a look at the build.

    https://ci.appveyor.com/project/LauritzITDevelopment/lauritz-lots/build/118 <https://ci.appveyor.com/project/LauritzITDevelopment/lauritz-lots/build/118>

    I will keep digging, but any ideas is greatly appreciated :-)

    Regards
    Bjarne

  6. Support Staff 6 Posted by Feodor Fitsner on 02 Mar, 2015 02:31 PM

    Feodor Fitsner's Avatar

    Will take a look. As a quick note - make sure app.config for the project with tests has "copy always" set in Visual Studio.

    -Feodor

  7. Support Staff 7 Posted by Feodor Fitsner on 02 Mar, 2015 05:54 PM

    Feodor Fitsner's Avatar

    OK, I did a simple xUnit 2.0 test reading settings and connection string config and it worked like a charm.

    Test: https://github.com/FeodorFitsner/xunit-20-tests/blob/master/Xunit20...
    App.config: https://github.com/FeodorFitsner/xunit-20-tests/blob/master/Xunit20...
    Build results: https://ci.appveyor.com/project/FeodorFitsner/xunit-20-tests/build/...

    Note, that app.config should have set "Copy always": https://github.com/FeodorFitsner/xunit-20-tests/blob/master/Xunit20... and when project build there must be <assembly>.dll.config in output directory.

  8. 8 Posted by Bjarne Riis on 03 Mar, 2015 08:31 AM

    Bjarne Riis's Avatar

    I did the same thing. Made a new test project in the same solution, and everything works perfectly. Spooky :-)

    But al is good. I have a workaround and will keep digging. Thank you for your help !

    Regards
    Bjarne

  9. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 01:54 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac