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

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>

Related

SQL Server using Windows Authentication in Wildfly as service

I'm configuring a datasource to use windows authentication with SQL Server.
I put the DLL sqljdbc_auth.dll in C:\Program Files\XXXX\wildfly-10.1.0.Final\bin
Stating Wildfly using standalone.bat works fine.
But using windows service I got this error:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "Scope_Build36" requested by the login. The login failed. ClientConnectionId:831c2f7f-4352-4467-b54f-a6eb1369d6e9
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:251)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:81)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$1LogonProcessor.complete(SQLServerConnection.java:2825)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:3079)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2360)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:43)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2346)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:6276)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1793)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1404)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1068)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:904)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:451)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1014)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:321)
... 44 more
DataSource configuration:
<datasource jta="true" jndi-name="java:/datasources/PortalScopeWeb_Scope" pool-name="PortalScopeWeb_Scope" enabled="true" use-ccm="true">
<connection-url>jdbc:sqlserver://RI001421D\SQLEXPRESS:1433;databasename=Scope_Build36;integratedSecurity=true</connection-url>
<driver>sqlServer</driver>
<security>
<security-domain>securityDomainPortalScopeWeb_Scope</security-domain>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<validate-on-match>true</validate-on-match>
<background-validation>false</background-validation>
</validation>
</datasource>
Putting DDL in folder C:\Program Files\XXXX\wildfly-10.1.0.Final\bin\service\amd64 don't solved the problem.
you can use a .udl file to test and verify your connection.
In you desktop create a new .txt file, and rename it like "test.udl". Now, open it, and you can configure and test your connection. When you have the connection ready, you can open the .udl file with notepad and copy connection string.
here you have a reference: udl reference
hope this help!

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

How to make the application read keys from app.config file of class library dynamically

My requirement is as follows.
1)I want to use the application settings to read a location path and use it in my project to read the files in that folder.
--- I achieved this by creating a setting with the path and I used to read the path from that settings in the project as follows
Properties.Settings.Default.XMLModelPath
2)Now the actual requirement is I want that app.config of the class library to be available in the bin so that I can update the path if there are any changes required later and every time I run the application, the settings of that project should read this file and update its value.
Is there a way to achieve this or suggest any other possible ways.?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MyClass.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<MyClass.Properties.Settings>
<setting name="XMLModelPath" serializeAs="String">
<value>C:\Resources\</value>
</setting>
</MyClass.Properties.Settings>
</applicationSettings>
</configuration>
This is my app.config file of the class. I want this to be available in bin and the settings of the project to be updated everytime I run my application.

Encrypt XML File with connection strings

I have tried encrytping the ConnectionStrings section of my 'ApplicationConfiguration.xml' file but it is not working correctly.
I pass my code the name and path of the xml file and it generates a new file but ive noticed if I pass in ANY file, text or xml it generates a new file anyway.
This is my xml file.
<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0.0.0">
<Database defaultDatabase="Local SQL Express">
<ConnectionStrings>
<ConnectionString displayName="Local SQL Express">Data Source=127.0.0.1;Initial Catalog=testDB;User ID=USER1;Password=Password1</ConnectionString>
<ConnectionString displayName="Local SQL">Data Source=127.0.0.1;Initial Catalog=testDB;User ID=USER2;Password=Password2</ConnectionString>
<ConnectionString displayName="Remote SQL">Data Source=127.0.0.1;Initial Catalog=testDB;User ID=USER3;Password=Password3</ConnectionString>
</ConnectionStrings>
</Database>
</Configuration>
Ive tried using the 'DataProtectionConfigurationProvider' and the 'RSAProtectionConfigurationProvider' but to no avail.
The reason for using these is so my application can read them without me having to do any decryption within the application.
Thanks
Kev

Running MSTest with tests against different databases

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.

Resources