473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How Oledb connection should be Declared

Hello
I m new in asp.net c#.
How to declare a oledbconnection object in asp.net c#.
Means should it be declared as a static or public?
ex:- suppose the object is
OleDbConnection con;
Whether it should be
static OleDbConnection con;
Or
public OleDbConnection con;
Sep 27 '10 #1
7 2989
Frinavale
9,735 Expert Mod 8TB
The Public scope modifier indicates that the variable is accessible other code. This means that other code can access and use the variable.

The Static modifier indicates that this variable is static/shared amongst all instances of the class. So if you have instantiated 4 instances of the ABC class (you have 4 ABC objects)...all 4 objects will share the same variable.

Be very careful about sharing connections between classes! You could experience problems while opening/closing the connection if another class is using the same connection.

-Frinny
Sep 27 '10 #2
mzmishra
390 Expert 256MB
static keyword allows you to make a variable/object/method be "shared" across all instances of a given object.
A public is an access modifier which means that it is the scope of this construct is public i.e. anyone can use it.

You can read this article to get different Variable and Method Scope in Microsoft .NET
http://msdn.microsoft.com/en-us/library/ms973875.aspx
Sep 27 '10 #3
Hello Sir,

Thanx
Actualy i hav a single database connection used in application, And I m facing the same problem of Opening/ Closing Connection. But It occurs sometimes, and sometimes it Works.
I am using "static OledbConnection con;" and it is being used in all functions

What should I do To fix that problem? and When Should I open/ Close Connection?
Sep 28 '10 #4
Frinavale
9,735 Expert Mod 8TB
You should only open a connection when it is needed and after you have finished with it you should close it.

The problem with using a static connection is that some objects are going to try opening and closing the connection while others are using it.

I strongly recommend against this approach...unless you want to take the time to implement a solution that works around the problem...but you'll probably run into other problems along the way.

This will become a bigger problem as your site becomes more active.


-Frinny
Sep 28 '10 #5
Yes Sir, I will Fit it into my mind.

I am Using MS-access. Is There Any Problem With MS-Access database in case of concurrency?
Sep 29 '10 #6
NeoPa
32,556 Expert Mod 16PB
Access databases can handle concurrency. My only experience of controlling this is within the options of the Application though.

It is generally considered that it doesn't handle many concurrent connections well though. Access as a back-end for web based applications should probably only be used sparingly and in circumstances where you know it to work and know that the usage will never grow beyond what Access can handle well.
Oct 1 '10 #7
Ok Thank you, Sir
Oct 2 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mathew Vording | last post by:
Hi. I have an application that after using it for a while, continually forcing it to hit the database it will fail on connection open with the OLEDB "Unspecified Error" message. ...
2
by: MasterChief | last post by:
I have a OLEDB Connection String that is working very well for me. My question is that I read that you can store the Connection String in a seperate include file or somewhere else. I am just...
0
by: Jim Heavey | last post by:
I created a UDL file on my desktop. I then double click on the file and identified the provider I wanted to use (IBM OLEDB) and my user name and password. I then tested the connection and tested...
0
by: uaurgent dragon | last post by:
I am new to database programming,I know how to make odbc(dsn) connection,Now i am struugling with olebd coonection and how to do coding . make oledb connection to store data in msaccess table...
0
by: Randy | last post by:
Hi,all I met a strange problem, I connected to access database using oledb connection, connection string like "Provider=Microsoft.Jet.OLEDB.4.0; Data...
0
by: Rashmi R | last post by:
Hi All, Our service is a custom builtin server using ACE framework in VC++. The connection handling is by ODBC. But now we need to change the connection handling to OLEDB. I tried to change the...
1
by: Flupke | last post by:
Hello everyone, I'm trying to make a OLEDB-connection between VB.Net (Visuel Studio 2005) and an Access-2003 database. This works smoothly and without a single problem on a Windows XP desktop...
1
by: Flupke | last post by:
I'm trying to set up an oledb connection between vb.net in visual studio 2005 and an access 2003 database. This works without a single problem under windows XP but not on a laptop configured with...
2
mafaisal
by: mafaisal | last post by:
Hello I am Using Vb.Net 2005 And Sql2005 See This Dim RsSave as new adodb.recordset RsSave.open "Select * From Table Where 1=2 ",Con,CursorTypeEnum.adOpenDynamic,...
1
by: ErikJL | last post by:
I have a simple webservice that performs a SELECT query against a database, and then an INSERT statement on the same database/table. The problem arises at the time when we create the second OleDB...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.