Getting SQL Express Connection String instead of my ODBC Connection String

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am attempting to use my Web.Config file to be the source for all connection strings in my app. I am only using a single project file. I confirmed the location of my Web.Config file. I read several other postings but all of the posted answers did not change
the situation. So first, the code:
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Odbc;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DataClass
/// </summary>
public class DataClass : IDataClass
{
public string ODBC_CS { get; set; }
public string SQLFF_CS { get; set; }
public DataTable INVAUD { get; set; }
public DataTable SCICCD { get; set; }
public DataTable INVBAL { get; set; }
public DataClass()
{

// Set SQLFF_CS & ODBC_CS
System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Web.config");
if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
{
System.Configuration.ConnectionStringSettings odbccs = rootWebConfig.ConnectionStrings.ConnectionStrings["AS400ConnectionString"];
System.Configuration.ConnectionStringSettings sqlcs = rootWebConfig.ConnectionStrings.ConnectionStrings["FillableFormsConnectionString"];
if (sqlcs.ToString() != "" && sqlcs.ToString() != null) SQLFF_CS = sqlcs.ToString();
if (odbccs.ToString() != "" && odbccs.ToString() != null) ODBC_CS = odbccs.ToString();
};
}[/code]
The correct value is returned for sqlcs connection string.
However, the odbccs connection string is returned as the Microsoft default:
{data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true}
The ASP.Net generated connection string (which works on ASP.Net) is:
DSN=xxxxxxx; UID=yyyyyy
This should be simple, but Ive spent 2.5 hours on it and my DBA is stumped too...
Its an IBM iSeries AS400 database. When I hard-code the connection string into my C# code, there are no problems. Its only when I try to access it on the web.config file.
I attempted to build a connection string based on connectionstrings.com, but I got the same result.
<hr class="sig Interns make work interesting...Like how papercuts break a days monotony.

View the full article
 
Back
Top