multiple connections in web.config using enterprise library 2.0

Topics: Data Access Application Block
Apr 20, 2007 at 11:42 PM
Hello,

I am using Enterprise library 2.0. I am trying to create multiple connection string in my web.config file.

My web.config file looks like this

<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<connectionStrings>
<add name="Connection String" connectionString="server=abcdef;database=team;PWD=pass;UID=sa;"
providerName="System.Data.SqlClient" />
<add name="Connection String1" connectionString="server=abcdef1;database=team1;PWD=pass;UID=sa;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings />

I am accessing this in my program through this code

protected void Page_Load(object sender, EventArgs e)
{
{
Database db = DatabaseFactory.CreateDatabase(ConfigurationManager.AppSettings"Connection String");
string sqlCommand = "sp_getUserId";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

// Retrieve products from the specified category.
db.AddInParameter(dbCommand, "NTLogOn", DbType.Int32, "test");

// DataSet that will hold the returned results
DataSet productsDataSet = null;

productsDataSet = db.ExecuteDataSet(dbCommand);
//return productsDataSet;


}
}

On the first line, I get an error The value can not be null or string or empty.\r\nParameter name: id. I am getting this error on
Database db = DatabaseFactory.CreateDatabase(ConfigurationManager.AppSettings"Connection String"); this line.

Any help will be appreciated.

Thanks.
Apr 21, 2007 at 12:11 AM
You should not use the AppSettings property with the DatabaseFactory, since the connection string is not stored in that section. Instead you just need to do this:
Database db = DatabaseFactory.CreateDatabase("Connection String");
HTH
Tom
Apr 22, 2007 at 9:50 PM
I tried this with connection string and I am getting this error below:

"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<connectionStrings>

<add name="Connection String" connectionString="server=abcdef1;database=team1;PWD=pass;UID=sa;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings /
Apr 22, 2007 at 11:15 PM
I don't think I can add anything more than what's already in your error message. The DAAB is successfully talking to the SQL Server, but the SQL Server has decided it's not going to let you connect with its current configuration.

Tom
Apr 23, 2007 at 11:17 AM
Try adding the port after the servername.

<add name="Connection String" connectionString="server=abcdef1,1403;database=team1;PWD=pass;UID=sa;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings /