0

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.

1 Answer 1

1

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 ....
}
Sign up to request clarification or add additional context in comments.

8 Comments

ok so should that replace my section <applicationSettings> <TXExportNet.My.MySettings> <setting name="ConnString" serializeAs="String"> <value>Data Source=SerSql;Initial Catalog=Xray;User ID=XUSERX;Password= xxxxxxxxxx</value>
Or should it be placing that line in each of the places where the main class references the connection string?
Replace it where your class references the connection string.
More of what I mean is can I replace in my App.config the section that was <setting name="ConnString" as SerializeAs="String"> with this code but have it be string ConnString = ConfigurationManager.ConnectionString["TXConnString"].ConnectionString; and be able to leave all the places in code that are already pointed at "ConnString" as they are?
I changed my answer to show what should be in your config file and your source code file (using C#). In the app.config you can remove the <setting name ...> since you have the new <connectionStrings> section. Then in your source code you read from the config file and store the connection string in whatever variable your previous code used. In my example I called the variable connectionString.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.