Reputation: 99
Alright I am working with an older legacy application which has been converted from Visual Studios 2008 to Visual Studios 2010.
I was charged with making a minor update to the code of this existing application. I did the correction everything worked fine and the application did exactly what it was supposed to do except this application must be run from a Sql Server job. But every time I run the job from Sql Server 2008 using the Job Activity Monitor the job fails and gives the following error.
DTSRun: Loading... Error: -2147467259 (80004005); Provider Error: 17 (11) Error string: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. Error source: Microsoft OLE DB Provider for SQL Server
I am under the impression that the issue is related to way this old program does its connection string.
Below is an example to the old connection string (though I have changed some elements such as server names etc for security reasons)
<applicationSettings>
<TXExportNet.My.MySettings>
<setting name="ConnString" serializeAs="String">
<value>Data Source=SerSql;Initial Catalog=Xray;User ID=XUSERX;Password= xxxxxxxxxx</value>
this looks to be a very old way of doing connection strings so I wanted to update to a more regular method of connection string in a hopes that would correct the issue.
So I commented out the old connection string and added the following in the App.config file.
<connectionStrings>
<add name="TXConnString" connectionString="Data Source=SerSql.CXXX.INT;Initial Catalog=Xray;User ID=XUSERX; Password=xxxxxxxxxx" providerName="System.Data.OleDb"/>
I of course went through the program code and changed all the old "ConnString" references to the new "TXConnString"
However when I ran a Debug of the program I got the following error.
The settings property 'TXConnString' was not found.
I have obviously done something wrong but I am uncertain how to correct the issue aside from reverting to the previous version.
Any insight on what might be causing the issue or Suggestions would be great.
Upvotes: 0
Views: 1266
Reputation: 166
If you are using the connectionStrings tag instead of the applicationSettings tag you access the connection string differently. Use ConfigurationManager to retrieve your connection string.
From app.config file
<connectionStrings>
<add name="TXConnString" connectionString="Data Source=SerSql.CXXX.INT;Initial Catalog=Xray;User ID=XUSERX; Password=xxxxxxxxxx" providerName="System.Data.OleDb"/>
</connecectionStrings>
In your source code:
using System.Configuration;
string connectionString = ConfigurationManager.ConnectionStrings["TXConnString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
... insert database code here ....
}
Upvotes: 1