Sunday, March 11, 2012
Bi-Directional Updating Databases on same SQL server
Thanks,
Memphodave
Message posted via http://www.sqlmonster.com
Have a look at bi-directional transactional replication.
it is covered in SP3 books online.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
"David Walpole via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:be07a9381051493195afb35c1f13161d@.SQLMonster.c om...
> I am trying to separate two applications sharing the same database and a
few tables(like t_employee) in a phased approach. How can I best setup a
bi-directional update of this t_employee table when updated by either
application?
> Thanks,
> Memphodave
> --
> Message posted via http://www.sqlmonster.com
Thursday, February 16, 2012
Best way to pervent unused and left open connection to sql
Hello every one i had a design question.
What would be the best way to approach a problem such as a perventing unsed and left open sql connections
i have written a class called DataBase Manger but my question is should this class be static or none-static. right now the way i have is something like this
private SqlConnection Get() {
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["StringConnetionName"].ConnectionString);
sqlCon.Open();
return sqlCon;
}
/// <summary>
/// Closes a connection to the Database
/// </summary>
/// <param name="sqlCon"> Database connection to close</param>
private void Let(SqlConnection sqlCon) {
sqlCon.Close();
sqlCon = null;
}
then for example to run a store proc i have
public int RunProc(string procName,params SqlParameter[] p) { SqlConnection con = Get();try {using (SqlCommand cmd = CreateCommand(con, procName, p)) { cmd.ExecuteNonQuery();return (int)cmd.Parameters["ReturnValue"].Value; } }finally { Let(con); } }
now every time in any class or method i need to create a new Database manager and call the run proc object. Would it be a better desing to make this class static? so it would be just
DataBaseManger.RunProc(blah,blah)
or is it a better OO design to have it the way i have it. is is more secure in a webapplication? can these connections be hijacked?
thanks in adanvce, any help would greatly be apperiated. or any link to any related tutorials
thanks,
Amir
if you consider the design of the old MS Data Access Application Block (SqlHelper), you will see that virtually all the methods are static methods.
This is a very convenient approach and works well.
Rather than reinvent the wheel, why not look at incorporating the new data access application block from the enterprise library?
Sunday, February 12, 2012
Best way to create dynamic update statement
stored procedure, that can handle recieving varying input paramters and
update the approporiate columns.Depends on the requirements but one possibility is to use NULL
parameters to represent values that shouldn't be changed:
UPDATE YourTable
SET col1 = COALESCE(@.col1, col1),
col2 = COALESCE(@.col2, col2),
col3 = COALESCE(@.col3, col3)
... etc
WHERE ...
--
David Portas
SQL Server MVP
--|||>> In general, What is the best approach in creating a dynamic update
stored procedure, <<
In general, building dynamic is a bad idea. It says that you don't
know what you are doing, so you are turning over control of the system
at runtime to any random user, present or future. SQL is a compiled
language, not like BASIC.|||what would be wrong with using:
UPDATE YourTable
SET col1 = COALESCE(@.col1, col1),
col2 = COALESCE(@.col2, col2),
col3 = COALESCE(@.col3, col3)
... etc
WHERE ...
if i want to have one stored procedure to update a table.|||jw56...@.gmail.com wrote:
> if i want to have one stored procedure to update a(ny) table.
what would be wrong
--Strider|||jw56...@.gmail.com wrote:
> if i want to have one stored procedure to update a(ny) table.
what would be wrong
--Strider|||I think this is just some confusion over terminology. The term "dynamic
update" or "dynamic code" refers to code that references metadata
(usually table and column names) dynamically - elements of the code
being constructed at runtime. This is not generally good practice for
various reasons to do with performance, security, maintainability and
modular design. In your case however, no dynamic code is necessary.
--
David Portas
SQL Server MVP
--
Best way to copy a replicated database?
replication on the existing database. Is the best approach to simply script
out the database, do an export of the data, then recreate on the other end
and set up a new publication?
Earl,
if it is the publisher or the subscriber, as long as the machine name is
different in practice you'll need to reinitialize. You caould do a nsync
one, provided you could ensure the data is synchronized. This can be
achieved by stopping all activity during the process, or by using
datacompare after the restore. After that, you'll need to recreate the
publication (if publisher) and initialize.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||Thanks Paul. These are PocketPCs, so it sounds like the goal should be to
gather up one last round of data, then create a new database, load the data,
then create a new publication and initialize?
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:untCSjg2FHA.2492@.TK2MSFTNGP09.phx.gbl...
> Earl,
> if it is the publisher or the subscriber, as long as the machine name is
> different in practice you'll need to reinitialize. You caould do a nsync
> one, provided you could ensure the data is synchronized. This can be
> achieved by stopping all activity during the process, or by using
> datacompare after the restore. After that, you'll need to recreate the
> publication (if publisher) and initialize.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>
|||Earl,
that sounds like a pretty clean way of doing it.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)