Running MSTest with tests against different databases - database

I would like to ask what is the best way to execute a setup like the following:
We have tests suite that is compiled, and in the app.config file I have 6-7 different connection strings to different databases. I would like to run the tests suite against every connection, and I hoped to parametrize in some way this process - something like setting the name of the connection and passing it on to the testrun as a parameter. What I figured out so far is that I can use different localconfigrun files and through deployment items I can feed a xml/txt file with the required value, but is there a nicer and lighter solution? I need just to send a key/value pair or simple string to configure my base class inside the test suite.
I am using tfsbuild but I can use the mstest thrugh other environments as well (pure msbuild, etc.)
Thanks in advance.

I have had a similar issue. This is what I did:
My app.config looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ConenctToInputDB" value="InputDev" />
<add key="ConnectToOutputDB" value ="OutputDev"/>
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<connectionStrings>
<add name="LocalConnection" connectionString="YOUR CONNECTION STRING HERE" />
<add name="InputDev" connectionString="YOUR CONNECTION STRING HERE" />
<add name="InputCert" connectionString="YOUR CONNECTION STRING HERE"/>
<add name="OutputDev" connectionString="YOUR CONNECTION STRING HERE/>
<add name="OutputCert" connectionString="YOUR CONNECTION STRING HERE" />
<add name="InputProd" connectionString="YOUR CONNECTION STRING HERE/>
<add name="OutputProd" connectionString="YOUR CONNECTION STRING HERE" />
</connectionStrings>
In this secenario, I have 2 dbs I connect to and I have 3 different connection strings for each (Development, Certification and Production)
Add this to the bottom of your project file (right click on the project and unload it). Make sure you add it before the </project> tag. (You will need to install the MSBuild Community Tasks for this to work. They can be downloaded for free from: http://msbuildtasks.tigris.org/ (Make sure you get a nightly build))
<PropertyGroup>
<!--Import the MSBuild community tasks so we can update xml-->
<MSBuildCommunityTasksPath>C:\PathToMSBuildCommunityTasks\MSBuildTasks</MSBuildCommunityTasksPath>
<SubstitutionsFile Condition="'$(Configuration)' == 'Debug'">DevAppSettings.xml</SubstitutionsFile>
<SubstitutionsFile Condition="'$(Configuration)' == 'Cert'">CertAppSettings.xml</SubstitutionsFile>
<SubstitutionsFile Condition="'$(Configuration)' == 'Prod'">ProdAppSettings.xml</SubstitutionsFile>
</PropertyGroup>
<Import Project="C:\PathToMSBuildCommunityTasks\lib\MSBuildTasks\MSBuild.Community.Tasks.Targets" />
<Target Name="AfterBuild">
<!--Update the app config to have the correct environment paths-->
<Message Text="Updating $(MSBuildProjectName) config to $(Configuration)" Importance="high"></Message>
<XmlMassUpdate ContentFile="$(OutDir)\$(MSBuildProjectName).dll.config" SubstitutionsFile="..\..\$(SubstitutionsFile)" />
</Target>
This will replace the <appSettings> section of the app.config file based on the current configuration. You will need to make new new configurations (I called them Cert and Prod).
The last step is to make a file for each configuration (I called them DevAppConfig.xml, CertAppConfig.xml, ProdAppConfig.xml)
In each file should look like this (this one is for the Certification Configuration):
<?xml version="1.0" encoding="utf-8"?>
<!--This file is used by the build files to merge in solution wide app settings
Some projects contain files that have an AppSetting section (usually in App.config). Those projects have
and AfterBuild event in the project file that substitues this xml tree over the the normal xml tree.-->
<configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">
<appSettings>
<add xmu:key="key" key="ConenctToInputDB" value="Cert"/>
<add xmu:key="key" key="ConnectToOutputDB" value="ESPCert"/>
</appSettings>
</configuration>
all of this, once installed will make the file that is output by app.config be auto changed based on the configuration you are compiling. This code works for both compiling in the IDE and in Team Build.

Related

BVN404 gadget showing in local dev, but not EpiServer integration enviornment

I am able to access this gadget in my local dev environment, but not integration, as you can see below:
Local dev:
Integration:
I double checked the BVN settings from here: https://github.com/Geta/404handler#configuration. They are setup like this in my web.config:
<section name="bvn404Handler" type="BVNetwork.NotFound.Configuration.Bvn404HandlerConfiguration, BVNetwork.EPi404" />
<episerver.shell>
<publicModules rootPath="~/modules/" autoDiscovery="Modules" />
<protectedModules rootPath="~/EPiServer/">
<add name="BVNetwork.404Handler" />
<bvn404Handler handlerMode="On">
<providers>
<add name="Custom Handler" type="CompanyName.Business.CustomPageNotFoundHandler, companyname-cms" />
</providers>
</bvn404Handler>
There is not a securedComponents section, though I did try to add one with allowedRoles="Administrator", allowedRoles="*", and allowedRoles="Everyone" for testing purposes.
Any ideas why the gadget can't be viewed when published?
The issue was that the BVN zip file did not publish to the modules folder for some reason. After adding it back, it worked as expected.
Nuget installations sometimes misses the protectedmodules section
Ensure the BVNetwork.404Handler is in your protectedModules collection in web.config. Nuget sometimes miss that.
<episerver.shell>
<protectedModules rootPath="~/EPiServer/"> <!-- this line may vary -->
<!-- other modules -->
<add name="BVNetwork.404Handler" />
</protectedModules>
</episerver.shell>

How to add Azure SQL Server connection string to app.config in Windows Forms?

I'm trying to add an Azure SQL Server connection string into my app.config file, but there are red underlines all over the connection string when I try to copy and paste it from Azure. I'm using Windows Forms in Visual Studio.
Here is my connection string:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="AddSales"
Server="tcp:Sales99.database.windows.net,1433;Initial" Catalog="Sales;Persist" Security="" Info="False;User" ID=""{your_username};Password=""{your_password};MultipleActiveResultSets=""False;Encrypt=""True;TrustServerCertificate="False;Connection" Timeout="30"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Is there a way to fix this issue? Please advise.
Your config is just plain wrong - you need to have an attribute connectionString in your config that contains all the details about the connection - something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="AddSales"
connectionString="Server=tcp:Sales99.database.windows.net,1433;Initial Catalog=Sales;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
I also had this issue when I try to copy & paste connection string from the Azure database. This is connection string that worked for me.
Server=tcp:[serverName].database.windows.net;Database=myDataBase; User ID=[LoginForDb]#[serverName];Password=myPassword;Trusted_Connection=False; Encrypt=True;
This also works.
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=tcp:ServerName.database.windows.net,1433;Initial Catalog=DatabaseName;Integrated Security=False;User Id=username#servername;Password=password;Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />
If you need additional info, please visit these sites:
https://www.connectionstrings.com/sql-azure/
https://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx

Configuration system failed to initialize reading app.config file <oracle.manageddataaccess.client>

While reading from my app.config file using vb.net I get a 'Configuration system failed to initialize' error.
The error is occurring with the oracle.manageddataaccess.client
tag.
I am using oracle.manageddataaccess.dll using odp.net to connect to the database.
As we have a number of databases connections I would prefer to keep using the oracle tnsnames.ora file instead of putting in the database alias entry into the app.config file.
If I remove the oracle.manageddataaccess.client tag the vb.net code is reading the app.config without any issue ( I am able to read from ConnectionStrings tag).
The contents of the app.config file is below.
A second issue we have is that when ODP.NET installed when running .Net applications it won't pick up the TNSNAMES.ORA file from the oracle home folder.
It is picking up the TNSNAMES.ORA file from the TNSNAMES.ORA file in the folder
C:\Program Files (x86)\Oracle Developer Tools for VS2015\network\admin.
If we remove the tnsnames.ora file from this folder the code will not pick up the TNSNAMES.ORA file in the oracle home folder.
Thanks
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<oracle.manageddataaccess.client>
<version number="*">
<settings>
<setting name="tns_admin" value="E:\oracle11\product\11.2.0\client_1\network\admin" />
</settings>
</version>
</oracle.manageddataaccess.client>
<connectionStrings>
<add name="ConString" connectionString="Data Source=dbname;User ID=userid;Password=pw;"
providerName="Oracle.ManagedDataAccess.Client"/>
</connectionStrings>
</configuration>

Error: 26 - Error Locating Server/Instance Specified (Tried many things but couldn't find solution)

This question is already on Stack Overflow. But nobody solve my issue.
When I open my webpage (on my uploaded website on server) in which I am using database connectivity below error comes -
http://puneetchawla-001-site1.smarterasp.net/blog.aspx
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)
Searched on Google and found many thing and applied it but no one solved my issue.
Windows service called "SQL Server Browser" and start the service (I have enabled it).
Enabled incoming port TCP 1433 ( I have done this).
My web.config file -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<connectionStrings>
<add name="myWebsite" connectionString="Data Source=.\sqlexpress;Initial Catalog=myWebsite;Integrated Security=True; " providerName="System.Data.SqlClient" /> </connectionStrings>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
I have uploaded my website here - http://www.smarterasp.net
and their connection string samples for MSSQL are below-
"Data Source=SQL5014.Smarterasp.net;Initial Catalog=DB_9D58DA_myWebsite;User Id=DB_9D58DA_myWebsite_admin;Password=YOUR_DB_PASSWORD;"
I did changes in web.config based on our samples but didn't get solution.
I think, there will be only changes in web.config and rest all are correct.
You had not written the connection string (as specified in sample) in web.config file.
Your web.config file should be like
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<connectionStrings>
<add name="myWebsite" connectionString="Data Source=SQL5014.Smarterasp.net;Initial Catalog=DB_9D58DA_myWebsite;User Id=DB_9D58DA_myWebsite_admin;Password=YOUR_DB_PASSWORD;" /> </connectionStrings>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Just change your web.config file and you will get the solution.

SQL Server Project Automate Unit Testing

I have a SQL Server (2012) project in VS2013. I also have an app.config with Local configuration and [tfsbuildserver].sqlunittest.config with server connection string and a relative path.
When performing a check-in executes a build definition that makes deploy and run the tests. The deploy done correctly, but when tests throws me the following error:
An error occurred while SQL Server unit testing settings were being read from the configuration file. Click the test project, open the
SQL Server Test Configuration dialog box from the SQL menu, add the
settings to the dialog box, and rebuild the project.
app.config:
<configuration>
<configSections>
<section name="SqlUnitTesting" type="Microsoft.Data.Tools.Schema.Sql.UnitTesting.Configuration.SqlUnitTestingSection, Microsoft.Data.Tools.Schema.Sql.UnitTesting, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<SqlUnitTesting AllowConfigurationOverride="true">
<DatabaseDeployment DatabaseProjectFileName="[RELATIVEPATHLOCAL]"
Configuration="Release" />
<DataGeneration ClearDatabase="true" />
<ExecutionContext Provider="System.Data.SqlClient" ConnectionString="Data Source=[LOCALSERVER];Initial Catalog=[DATABASE];Integrated Security=True;Pooling=False"
CommandTimeout="30" />
<PrivilegedContext Provider="System.Data.SqlClient" ConnectionString="Data Source=[LOCALSERVER];Initial Catalog=[DATABASE];Integrated Security=True;Pooling=False"
CommandTimeout="30" />
</SqlUnitTesting>
</configuration>
[tfsbuildserver].sqlunittesting.config:
<SqlUnitTesting>
<DatabaseDeployment DatabaseProjectFileName="[RELATIVEPATHTFS]"
Configuration="Release" />
<DataGeneration ClearDatabase="true" />
<ExecutionContext Provider="System.Data.SqlClient" ConnectionString="Data Source=[SERVERTEST];Initial Catalog=[DATABASETEST];Persist Security Info=True;User ID=[USER];Password=[PASS];Pooling=False"
CommandTimeout="30" />
<PrivilegedContext Provider="System.Data.SqlClient" ConnectionString="Data Source=[SERVERTEST];Initial Catalog=[DATABASETEST];Persist Security Info=True;User ID=[USER];Password=[PASS];Pooling=False"
CommandTimeout="30" />
</SqlUnitTesting>
Tests run correctly locally. The error occurs when performing the build definition
Sorry for my English.
Thanks
Turns out the issue was that I had leading white space before the <SqlUnitTesting>, once these were removed the test ran as expected and remove
<?xml version="1.0" encoding="utf-8" ?>
URL: Link Resolved

Resources