Typed DataSet in DLL points to wrong database!

M

MaxGruven

I have a DLL that implements the Business and Data Layers for a number of
different websites. That DLL uses a Strongly Typed DataSet to interface to
the Data Source which is SQL Server.

There is a connection string in the DLL that is causes me grief. It points
at a particular instance of database. I hae to recompile the DLL for each
WebSite.

How can I re-use that DLL on different websites and have it point to
different instances of the Database without recompiling it?? Perhaps
configurable in Web.Config??

TIA,
George
 
Y

Yankee Imperialist Dog

set up a connection string in the web config of each site
<connectionStrings>
<add name="MyConnectionString" connectionString="Data
Source=sqlhost.server.com;Initial Catalog=trepiduscom;Persist Security
Info=True;User ID=MYID;Password=XXXX" providerName="System.Data.SqlClient"/>

</connectionStrings>

then create an appconfig name space:
using System.Configuration;

namespace MyCompany.MyName.Dal
{
/// <summary>
/// The AppConfiguaration class for the web.config file connection
string.
/// </summary>
public static class AppConfiguration
{
#region Public Properties

/// <summary>
/// Returns the connectionstring for the application.
/// </summary>
public static string ConnectionString
{
get
{
return
ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
}
}
}
}
then in your connection
area
using (SqlConnection Con = new
SqlConnectionAppConfiguration.ConnectionString))
{
......
......
......
}
just be sure to includ a using MyCompany.MyName.Dal; at the top
 
Y

Yankee Imperialist Dog

There is a paren missing
it should be
using (SqlConnection Con = new
SqlConnection(AppConfiguration.ConnectionString))
{
--
Share The Knowledge. I need all the help I can get and so do you!


Yankee Imperialist Dog said:
set up a connection string in the web config of each site
<connectionStrings>
<add name="MyConnectionString" connectionString="Data
Source=sqlhost.server.com;Initial Catalog=trepiduscom;Persist Security
Info=True;User ID=MYID;Password=XXXX" providerName="System.Data.SqlClient"/>

</connectionStrings>

then create an appconfig name space:
using System.Configuration;

namespace MyCompany.MyName.Dal
{
/// <summary>
/// The AppConfiguaration class for the web.config file connection
string.
/// </summary>
public static class AppConfiguration
{
#region Public Properties

/// <summary>
/// Returns the connectionstring for the application.
/// </summary>
public static string ConnectionString
{
get
{
return
ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
}
}
}
}
then in your connection
area
using (SqlConnection Con = new
SqlConnectionAppConfiguration.ConnectionString))
{
.....
.....
.....
}
just be sure to includ a using MyCompany.MyName.Dal; at the top
--
Share The Knowledge. I need all the help I can get and so do you!


MaxGruven said:
I have a DLL that implements the Business and Data Layers for a number of
different websites. That DLL uses a Strongly Typed DataSet to interface to
the Data Source which is SQL Server.

There is a connection string in the DLL that is causes me grief. It points
at a particular instance of database. I hae to recompile the DLL for each
WebSite.

How can I re-use that DLL on different websites and have it point to
different instances of the Database without recompiling it?? Perhaps
configurable in Web.Config??

TIA,
George
 
P

Peter Bromberg [C# MVP]

Since each web site would have its own web.config, set up the connection
string in the <connectionStrings... element
in the Assembly, you would get the proper connection string with:

ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;

Your assembly would need to have a reference to System.Configuration.

Peter
 
M

MaxGruven

Where do I put the reference to connection string in the BL/DL Assembly?

Does it go in Project/Properties/Settings or app.config or in code somewhere?

AND

What Connection String gets used when just working on the BL/DL Assembly
when there is no website (during development)??

TIA,
George

Peter Bromberg said:
Since each web site would have its own web.config, set up the connection
string in the <connectionStrings... element
in the Assembly, you would get the proper connection string with:

ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;

Your assembly would need to have a reference to System.Configuration.

Peter

MaxGruven said:
I have a DLL that implements the Business and Data Layers for a number of
different websites. That DLL uses a Strongly Typed DataSet to interface
to
the Data Source which is SQL Server.

There is a connection string in the DLL that is causes me grief. It
points
at a particular instance of database. I hae to recompile the DLL for each
WebSite.

How can I re-use that DLL on different websites and have it point to
different instances of the Database without recompiling it?? Perhaps
configurable in Web.Config??

TIA,
George
 
S

Steven Cheng [MSFT]

Hi George,

As for the TypedDataSet(in class library project)'s connectionstring
problem, it is a common question I've seen. Actually, you can override the
connectionstring in your consumer application(asp.net or other desktop)'s
app.config file.

For example, in your class library, when you created type dataset, it will
generate the following section in the class library's app.config file:

===============

<connectionStrings>
<add
name="ClassLibrary1.Properties.Settings.MYASPDBConnectionString"
connectionString="Data Source=localhost;Initial
Catalog=MYASPDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
===============

this is generated by the IDE for your typedataset. You can try adding such
a connectionstring entry in your calling application( the asp.net )'s
app.config file to override the default value(compiled in class library
assembly).

here are some former threads where I've mentioened something else about
such customziation of class library's project properties:

#app.config
http://groups.google.com/group/microsoft.public.dotnet.general/browse_thread
/thread/cba21e1cfca4585a/d3b4969cae7a600e

#Question on how to manage SQL Server connection string Options
http://groups.google.com/group/microsoft.public.dotnet.framework.webservices
/browse_thread/thread/e8b06265ba1c2b33/3c2a56cc046e4b1c

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
From: =?Utf-8?B?TWF4R3J1dmVu?= <[email protected]>
References: <[email protected]>
Subject: Re: Typed DataSet in DLL points to wrong database!
Date: Thu, 5 Jun 2008 15:41:02 -0700
Where do I put the reference to connection string in the BL/DL Assembly?

Does it go in Project/Properties/Settings or app.config or in code somewhere?

AND

What Connection String gets used when just working on the BL/DL Assembly
when there is no website (during development)??

TIA,
George

Peter Bromberg said:
Since each web site would have its own web.config, set up the connection
string in the <connectionStrings... element
in the Assembly, you would get the proper connection string with:

ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;

Your assembly would need to have a reference to System.Configuration.

Peter

MaxGruven said:
I have a DLL that implements the Business and Data Layers for a number of
different websites. That DLL uses a Strongly Typed DataSet to interface
to
the Data Source which is SQL Server.

There is a connection string in the DLL that is causes me grief. It
points
at a particular instance of database. I hae to recompile the DLL for each
WebSite.

How can I re-use that DLL on different websites and have it point to
different instances of the Database without recompiling it?? Perhaps
configurable in Web.Config??

TIA,
George
 
M

MaxGruven

That was it Steven!

Thanks for your help,
George

Steven Cheng said:
Hi George,

As for the TypedDataSet(in class library project)'s connectionstring
problem, it is a common question I've seen. Actually, you can override the
connectionstring in your consumer application(asp.net or other desktop)'s
app.config file.

For example, in your class library, when you created type dataset, it will
generate the following section in the class library's app.config file:

===============

<connectionStrings>
<add
name="ClassLibrary1.Properties.Settings.MYASPDBConnectionString"
connectionString="Data Source=localhost;Initial
Catalog=MYASPDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
===============

this is generated by the IDE for your typedataset. You can try adding such
a connectionstring entry in your calling application( the asp.net )'s
app.config file to override the default value(compiled in class library
assembly).

here are some former threads where I've mentioened something else about
such customziation of class library's project properties:

#app.config
http://groups.google.com/group/microsoft.public.dotnet.general/browse_thread
/thread/cba21e1cfca4585a/d3b4969cae7a600e

#Question on how to manage SQL Server connection string Options
http://groups.google.com/group/microsoft.public.dotnet.framework.webservices
/browse_thread/thread/e8b06265ba1c2b33/3c2a56cc046e4b1c

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
From: =?Utf-8?B?TWF4R3J1dmVu?= <[email protected]>
References: <[email protected]>
Subject: Re: Typed DataSet in DLL points to wrong database!
Date: Thu, 5 Jun 2008 15:41:02 -0700
Where do I put the reference to connection string in the BL/DL Assembly?

Does it go in Project/Properties/Settings or app.config or in code somewhere?

AND

What Connection String gets used when just working on the BL/DL Assembly
when there is no website (during development)??

TIA,
George

Peter Bromberg said:
Since each web site would have its own web.config, set up the connection
string in the <connectionStrings... element
in the Assembly, you would get the proper connection string with:

ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;

Your assembly would need to have a reference to System.Configuration.

Peter

I have a DLL that implements the Business and Data Layers for a number of
different websites. That DLL uses a Strongly Typed DataSet to interface
to
the Data Source which is SQL Server.

There is a connection string in the DLL that is causes me grief. It
points
at a particular instance of database. I hae to recompile the DLL for each
WebSite.

How can I re-use that DLL on different websites and have it point to
different instances of the Database without recompiling it?? Perhaps
configurable in Web.Config??

TIA,
George
 
S

Steven Cheng [MSFT]

You're welcome George,

Have a nice day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?TWF4R3J1dmVu?= <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: Re: Typed DataSet in DLL points to wrong database!
Date: Fri, 6 Jun 2008 06:54:01 -0700
That was it Steven!

Thanks for your help,
George

Steven Cheng said:
Hi George,

As for the TypedDataSet(in class library project)'s connectionstring
problem, it is a common question I've seen. Actually, you can override the
connectionstring in your consumer application(asp.net or other desktop)'s
app.config file.

For example, in your class library, when you created type dataset, it will
generate the following section in the class library's app.config file:

===============

<connectionStrings>
<add
name="ClassLibrary1.Properties.Settings.MYASPDBConnectionString"
connectionString="Data Source=localhost;Initial
Catalog=MYASPDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
===============

this is generated by the IDE for your typedataset. You can try adding such
a connectionstring entry in your calling application( the asp.net )'s
app.config file to override the default value(compiled in class library
assembly).

here are some former threads where I've mentioened something else about
such customziation of class library's project properties:

#app.config
http://groups.google.com/group/microsoft.public.dotnet.general/browse_thread
/thread/cba21e1cfca4585a/d3b4969cae7a600e

#Question on how to manage SQL Server connection string Options
http://groups.google.com/group/microsoft.public.dotnet.framework.webservices
/browse_thread/thread/e8b06265ba1c2b33/3c2a56cc046e4b1c

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
From: =?Utf-8?B?TWF4R3J1dmVu?= <[email protected]>
References: <[email protected]>
Subject: Re: Typed DataSet in DLL points to wrong database!
Date: Thu, 5 Jun 2008 15:41:02 -0700
Where do I put the reference to connection string in the BL/DL Assembly?

Does it go in Project/Properties/Settings or app.config or in code somewhere?

AND

What Connection String gets used when just working on the BL/DL Assembly
when there is no website (during development)??

TIA,
George

:

Since each web site would have its own web.config, set up the connection
string in the <connectionStrings... element
in the Assembly, you would get the proper connection string with:

ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;

Your assembly would need to have a reference to System.Configuration.

Peter

I have a DLL that implements the Business and Data Layers for a
number
of
different websites. That DLL uses a Strongly Typed DataSet to interface
to
the Data Source which is SQL Server.

There is a connection string in the DLL that is causes me grief. It
points
at a particular instance of database. I hae to recompile the DLL
for
each
WebSite.

How can I re-use that DLL on different websites and have it point to
different instances of the Database without recompiling it?? Perhaps
configurable in Web.Config??

TIA,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top