Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Shared Transaction Object

4 posts in DataWindow .NET Last posting was on 2004-12-06 22:27:13.0Z
FrankG Posted on 2004-12-03 21:59:23.0Z
Sender: 6a2c.41b0838e.1804289383@sybase.com
From: FrankG
Newsgroups: sybase.public.datawindow.net
Subject: Shared Transaction Object
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <41b0e1bb.7548.1681692777@sybase.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="-=_forums-1-dub41b0e1bb"
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 3 Dec 2004 13:59:23 -0800
X-Trace: forums-1-dub 1102111163 10.22.241.41 (3 Dec 2004 13:59:23 -0800)
X-Original-Trace: 3 Dec 2004 13:59:23 -0800, 10.22.241.41
Lines: 130
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.datawindow.net:879
Article PK: 125303

Finally got the shared connection working. Thanks to Suresh
Babu (our Java Expert)!!!! Objective was to minimize the
amount of code and make the connection seem as transparent
to the developer as possible - just like Powerbuilder does.
The class DatabaseConnectionManager is a singleton class.
You should probably finalize it using sealed, but the goal
was not to create the the perfect class (not yet anyhow).

My application is a MDI application. I wanted to share the
connection from the main MDI form. To do so, I created a
"global like" variable in the MDI form. Note it is public
static so we can easily use mySQLCA throughout the rest of
the application.

public static Sybase.DataWindow.Transaction mySQLCA;

Created private method in the same form to get an instance
of the transaction object.

private void InitializeConnection()
{
mySQLCA = DatabaseConnectionManager.getConnection();
}

Any window requiring access to the shared transaction object
needs to include a reference to the main MDI form. Notice
my main form (dbEdgeMDI) preceeds the name of the shared
transaction object when setting the transaction for a
datawindow.
dwc1.SetTransaction(dbEdgeMDI.mySQLCA);
dwc1.Retrieve();

Obviously need to add error handling to
DatabaseConnectionManager, along with methods to set the
parameters of the transaction object. The class also
automatically connects on instantiation. I should rename
the initialize method to OpenConnection (if it is not a
reserved word) and force other code to perform the actual
database connection.

Need the following classdeclaration for most of the work.
Change the namespace.

using System;
using System.Windows.Forms;

namespace dbEdge
{
/// <summary>
/// Summary description for DatabaseConnectionManager.
/// </summary>
public class DatabaseConnectionManager
{
//static private DatabaseConnectionManager dbConnMgr=null;
static private Sybase.DataWindow.Transaction
dbTransaction;


public static Sybase.DataWindow.Transaction
getConnection()
{
if (null == dbTransaction)
{
dbTransaction = new Sybase.DataWindow.Transaction();
initialize();
//dbConnMgr = new DatabaseConnectionManager();
}
//return the database transaction
return dbTransaction;
}

private static void initialize()
{
//Hardcode connection to SQL Server ODBC for now
//dbTransaction.
dbTransaction.DbParameter =
"ConnectString='DSN=myPubs;UID=;PWD=',DelimitIdentifier='No'
,CommitOnDisconnect='No'";
dbTransaction.Dbms = Sybase.DataWindow.DbmsType.Odbc;
dbTransaction.Connect();
}

public static void CloseConnection()
{
if (dbTransaction != null)
dbTransaction.Disconnect();
}
}
}

using System;
using System.Windows.Forms;

namespace dbEdge
{
/// <summary>
/// Summary description for DatabaseConnectionManager.
/// </summary>
public class DatabaseConnectionManager
{
//static private DatabaseConnectionManager dbConnMgr=null;
static private Sybase.DataWindow.Transaction dbTransaction;


public static Sybase.DataWindow.Transaction getConnection()
{
if (null == dbTransaction)
{
dbTransaction = new Sybase.DataWindow.Transaction();
initialize();
//dbConnMgr = new DatabaseConnectionManager();
}
//return the database transaction
return dbTransaction;
}

private static void initialize()
{
//Hardcode connection to SQL Server ODBC for now
//dbTransaction.
//ConnectString='DSN=myPubs;UID=;PWD=',DelimitIdentifier='No',CommitOnDisconnect='No'
dbTransaction.DbParameter = "ConnectString='DSN=myPubs;UID=;PWD=',DelimitIdentifier='No',CommitOnDisconnect='No'";
dbTransaction.Dbms = Sybase.DataWindow.DbmsType.Odbc;
dbTransaction.Connect();
}

public static void CloseConnection()
{
if (dbTransaction != null)
dbTransaction.Disconnect();
}
}
}


dfish Posted on 2004-12-03 22:26:38.0Z
From: dfish@_no_spam_sybase.com (Dave Fish [Team Sybase])
Newsgroups: sybase.public.datawindow.net
Subject: Re: Shared Transaction Object
Organization: Sybase Professional Services
Reply-To: nospam_dfish@sybase.com_nospam
Message-ID: <41b0e7d5.7803600@forums.sybase.com>
References: <41b0e1bb.7548.1681692777@sybase.com>
X-Newsreader: Forte Free Agent 1.21/32.243
NNTP-Posting-Host: vpn-dub-162.sybase.com
X-Original-NNTP-Posting-Host: vpn-dub-162.sybase.com
Date: 3 Dec 2004 14:26:38 -0800
X-Trace: forums-1-dub 1102112798 10.22.120.162 (3 Dec 2004 14:26:38 -0800)
X-Original-Trace: 3 Dec 2004 14:26:38 -0800, vpn-dub-162.sybase.com
Lines: 145
X-Authenticated-User: TeamSybase
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.datawindow.net:881
Article PK: 125306

Excellent! Thanks for figuring this out and posting the solution here.
You've freed up some time for me this weekend! :-)

Regards,
Dave Fish
Sybase

TeamSybase blogs: http://www.teamsybase.net/blogs

DataWindow.NET code examples available on CodeXchange:
http://datawindownet.codexchange.sybase.com

On 3 Dec 2004 13:59:23 -0800, FrankG wrote:

>This is a multi-part message in MIME format.
>
>---=_forums-1-dub41b0e1bb
>Content-Type: text/plain; charset="ISO-8859-1"
>Content-Transfer-Encoding: 7bit
>
>Finally got the shared connection working. Thanks to Suresh
>Babu (our Java Expert)!!!! Objective was to minimize the
>amount of code and make the connection seem as transparent
>to the developer as possible - just like Powerbuilder does.
>The class DatabaseConnectionManager is a singleton class.
>You should probably finalize it using sealed, but the goal
>was not to create the the perfect class (not yet anyhow).
>
>My application is a MDI application. I wanted to share the
>connection from the main MDI form. To do so, I created a
>"global like" variable in the MDI form. Note it is public
>static so we can easily use mySQLCA throughout the rest of
>the application.
>
>public static Sybase.DataWindow.Transaction mySQLCA;
>
>Created private method in the same form to get an instance
>of the transaction object.
>
>private void InitializeConnection()
>{
> mySQLCA = DatabaseConnectionManager.getConnection();
>}
>
>Any window requiring access to the shared transaction object
>needs to include a reference to the main MDI form. Notice
>my main form (dbEdgeMDI) preceeds the name of the shared
>transaction object when setting the transaction for a
>datawindow.
>dwc1.SetTransaction(dbEdgeMDI.mySQLCA);
>dwc1.Retrieve();
>
>Obviously need to add error handling to
>DatabaseConnectionManager, along with methods to set the
>parameters of the transaction object. The class also
>automatically connects on instantiation. I should rename
>the initialize method to OpenConnection (if it is not a
>reserved word) and force other code to perform the actual
>database connection.
>
>Need the following classdeclaration for most of the work.
>Change the namespace.
>
>using System;
>using System.Windows.Forms;
>
>namespace dbEdge
>{
> /// <summary>
> /// Summary description for DatabaseConnectionManager.
> /// </summary>
> public class DatabaseConnectionManager
> {
> //static private DatabaseConnectionManager dbConnMgr=null;
> static private Sybase.DataWindow.Transaction
>dbTransaction;
>
>
> public static Sybase.DataWindow.Transaction
>getConnection()
> {
> if (null == dbTransaction)
> {
> dbTransaction = new Sybase.DataWindow.Transaction();
> initialize();
> //dbConnMgr = new DatabaseConnectionManager();
> }
> //return the database transaction
> return dbTransaction;
> }
>
> private static void initialize()
> {
> //Hardcode connection to SQL Server ODBC for now
> //dbTransaction.
> dbTransaction.DbParameter =
>"ConnectString='DSN=myPubs;UID=;PWD=',DelimitIdentifier='No'
>,CommitOnDisconnect='No'";
> dbTransaction.Dbms = Sybase.DataWindow.DbmsType.Odbc;
> dbTransaction.Connect();
> }
>
> public static void CloseConnection()
> {
> if (dbTransaction != null)
> dbTransaction.Disconnect();
> }
> }
>}
>
>---=_forums-1-dub41b0e1bb
>Content-Type: text/plain; name="DatabaseConnectionManager.cs"
>Content-Transfer-Encoding: base64
>Content-Disposition: attachment; filename="DatabaseConnectionManager.cs"
>
>dXNpbmcgU3lzdGVtOw0KdXNpbmcgU3lzdGVtLldpbmRvd3MuRm9ybXM7DQoN
>Cm5hbWVzcGFjZSBkYkVkZ2UNCnsNCgkvLy8gPHN1bW1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RGlzY29ubmVjdD0nTm8nDQoJCWRiVHJh
>bnNhY3Rpb24uRGJQYXJhbWV0ZXIgPSAiQ29ubmVjdFN0cmluZz0nRFNOPW15
>UHVicztVSUQ9O1BXRD0nLERlbGltaXRJZGVudGlmaWVyPSdObycsQ29tbWl0
>T25EaXNjb25uZWN0PSdObyciOw0KCQlkYlRyYW5zYWN0aW9uLkRibXMgPSBT
>eWJhc2UuRGF0YVdpbmRvdy5EYm1zVHlwZS5PZGJjOw0KCQlkYlRyYW5zYWN0
>aW9uLkNvbm5lY3QoKTsNCgkJfQ0KDQoJCXB1YmxpYyBzdGF0aWMgdm9pZCBD
>bG9zZUNvbm5lY3Rpb24oKQ0KCQl7DQoJCQlpZiAoZGJUcmFuc2FjdGlvbiAh
>PSBudWxsKQ0KCQkJCWRiVHJhbnNhY3Rpb24uRGlzY29ubmVjdCgpOw0KCQl9
>DQoJfQ0KfQ0K
>
>---=_forums-1-dub41b0e1bb--


FrankG Posted on 2004-12-03 23:24:21.0Z
Sender: 75fe.41b0f4b5.1804289383@sybase.com
From: FrankG
Newsgroups: sybase.public.datawindow.net
Subject: Shared Transaction - my pleasure!
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <41b0f5a5.7607.1681692777@sybase.com>
References: <41b0e7d5.7803600@forums.sybase.com>
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 3 Dec 2004 15:24:21 -0800
X-Trace: forums-1-dub 1102116261 10.22.241.41 (3 Dec 2004 15:24:21 -0800)
X-Original-Trace: 3 Dec 2004 15:24:21 -0800, 10.22.241.41
Lines: 20
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.datawindow.net:882
Article PK: 125308

Hope this will qualify me for the 1.5beta. Need this same
object for ASP. I think it will be a little more
complicated. The DatabaseConnectionManager will need to
track current connections and grab an open pool. Suresh did
this in java, so we should be able to do the same for .net.

> Excellent! Thanks for figuring this out and posting the
> solution here. You've freed up some time for me this
> weekend! :-)
>
> Regards,
> Dave Fish
> Sybase
>
> TeamSybase blogs: http://www.teamsybase.net/blogs
>
> DataWindow.NET code examples available on CodeXchange:
> http://datawindownet.codexchange.sybase.com
>


DGerdner Posted on 2004-12-06 22:27:13.0Z
From: "DGerdner" <dave@ptax.org>
Newsgroups: sybase.public.datawindow.net
References: <41b0e1bb.7548.1681692777@sybase.com>
Subject: Re: Shared Transaction Object
Lines: 59
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: ool-4353a821.dyn.optonline.net
X-Original-NNTP-Posting-Host: ool-4353a821.dyn.optonline.net
Message-ID: <41b4dcc1$1@forums-1-dub>
Date: 6 Dec 2004 14:27:13 -0800
X-Trace: forums-1-dub 1102372033 67.83.168.33 (6 Dec 2004 14:27:13 -0800)
X-Original-Trace: 6 Dec 2004 14:27:13 -0800, ool-4353a821.dyn.optonline.net
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.datawindow.net:891
Article PK: 125316

I believe we found a similar solution. We created a static class
SharedConnection with a method getSharedConnection().

However, rather than always refer back to the MDI form, anything that needs
the connection does so in the following manner:

1. Include "using <namespace of the project>"
2. Include "using System.Data.Odbc"
3. Define a variable in the form:
private OdbcConnection sqlconnect =
SharedConnection.GetSharedConnection();

As a bonus, I used the same technique for a datawindow.net transaction
object. That also worked.

-Dave

SharedConnection (all hardcoded - this was a "proof of concept" program):

using System;
using System.Data.Odbc;
using System.Windows.Forms;

namespace Itrack
{
/// <summary>
/// Summary description for t_main.
/// </summary>
public class SharedConnection
{
private static string strDSN;
private static string strUserId;
private static string strPassword;
private static string strProvider;
private static string strConnString;
private static string strDatabase;
private static string strDBMS;
private static OdbcConnection MySharedConnection;

static SharedConnection()
{
strDSN = "itrack";
strUserId = "itrackuser";
strPassword = "xxxxxxx";
strProvider = "MSDASQL.1";
strDatabase = "itrack";
strDBMS="Odbc";
strConnString="DSN=itrack;UID=itrackuser;PWD=xxxxxxx";

}
public static OdbcConnection GetSharedConnection()
{
if (MySharedConnection == null)
{
MySharedConnection = new OdbcConnection();
MySharedConnection.ConnectionString=strConnString;
MySharedConnection.Op