473,796 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help! Need quick answer...

Does anyone know how to make common database connections "common" in all
aspx files? In other words, instead of creating a SQLConnection, then a
DataAdapter in every ASPX file for my application, I would like to "include"
them, or "import", say an ascx file. In ASP, all you needed to to was
include another .asp file to do this.

Many thanks,

Chad
Nov 18 '05 #1
6 1412
you mean open the connection once and reuse it without re-opening? DONT...
BAD BAD practice.
Now if you simply mean the string for the connection and such, put it in a
parent class that you have all the others inherit from.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Chad A. Beckner" <Ch*********@Pr ospectiveLink.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Does anyone know how to make common database connections "common" in all
aspx files? In other words, instead of creating a SQLConnection, then a
DataAdapter in every ASPX file for my application, I would like to "include" them, or "import", say an ascx file. In ASP, all you needed to to was
include another .asp file to do this.

Many thanks,

Chad

Nov 18 '05 #2
I would recommend you create a base class that inherits from Page that has
all that code. Then have all your pages inherit from the custom class
instead of from Page.

"Chad A. Beckner" <Ch*********@Pr ospectiveLink.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Does anyone know how to make common database connections "common" in all
aspx files? In other words, instead of creating a SQLConnection, then a
DataAdapter in every ASPX file for my application, I would like to "include" them, or "import", say an ascx file. In ASP, all you needed to to was
include another .asp file to do this.

Many thanks,

Chad

Nov 18 '05 #3
No, No, I don't want to keep the connection open. All I want is to create
some common code that will "allow" me to re-use a "standard" DataAdapter,
instead of re-creating the SQL connections on every page. Can you give me
some info (either code or a good website page) of where I could find an
example (a few mentioned inheriting from a custom class"???

Thanks,

Chad
"Chad A. Beckner" <Ch*********@Pr ospectiveLink.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Does anyone know how to make common database connections "common" in all
aspx files? In other words, instead of creating a SQLConnection, then a
DataAdapter in every ASPX file for my application, I would like to "include" them, or "import", say an ascx file. In ASP, all you needed to to was
include another .asp file to do this.

Many thanks,

Chad

Nov 18 '05 #4
>Does anyone know how to make common database connections "common" in all
aspx files? In other words, instead of creating a SQLConnection, then a
DataAdapter in every ASPX file for my application, I would like to "include"
them, or "import", say an ascx file. In ASP, all you needed to to was
include another .asp file to do this.


In Global.asax create a public shared variable something like this:

Public Shared DataSource As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0; Data Source=c:\inetp ub\db\data.mdb"

Then whenever you want to use it simpley use:

Global.DataSour ce

Hope this helps.

Blu
Nov 18 '05 #5
Ok, I have added it to my global.asa file, but when I try to view/edit the
sql statement, it says that I don't have an active connection. Ideas?

Chad

"BluDog" <nospam> wrote in message
news:o7******** *************** *********@4ax.c om...
Does anyone know how to make common database connections "common" in all
aspx files? In other words, instead of creating a SQLConnection, then a
DataAdapter in every ASPX file for my application, I would like to "include"them, or "import", say an ascx file. In ASP, all you needed to to was
include another .asp file to do this.


In Global.asax create a public shared variable something like this:

Public Shared DataSource As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0; Data Source=c:\inetp ub\db\data.mdb"

Then whenever you want to use it simpley use:

Global.DataSour ce

Hope this helps.

Blu

Nov 18 '05 #6
On Fri, 28 May 2004 13:54:12 -0500, "Chad A. Beckner"
<Ch*********@Pr ospectiveLink.c om> wrote:
Ok, I have added it to my global.asa file, but when I try to view/edit the
sql statement, it says that I don't have an active connection. Ideas?


Chad

You still need to create a connection when you need to use the
database, the above simply sets up a global connection string.

Here's what i do. I have created a class called data that i can used
anywhere in the project, this is for a oledb but it is easy enough to
change to SQL. I have a bunch of functions that i use regularly for my
database work:

<code>

Option Strict On

Imports System.Data.Ole Db

Public Class Data

#Region "Retrevial"

Public Shared Function GetRow(ByVal Table As String, ByVal Key As
Guid) As DataRow

Dim DataSet As DataSet = GetDataSet("SEL ECT * FROM " & Table &
" WHERE ID = {" & Key.ToString & "}")
If DataSet.Tables( 0).Rows.Count > 0 Then Return
DataSet.Tables( 0).Rows(0)

End Function

Public Shared Function GetRow(ByVal Table As String, ByVal Key As
String, ByVal KeyField As String) As DataRow

Dim DataSet As DataSet = GetDataSet("SEL ECT * FROM " & Table &
" WHERE " & KeyField & " = " & Key)
If DataSet.Tables( 0).Rows.Count > 0 Then Return
DataSet.Tables( 0).Rows(0)

End Function

Public Shared Function GetValue(ByVal Table As String, ByVal Field
As String, ByVal Key As Guid) As String

Dim DataSet As DataSet = GetDataSet("SEL ECT " & Field & " FROM
" & Table & " WHERE ID = {" & Key.ToString & "}")
If DataSet.Tables( 0).Rows.Count > 0 Then Return
DataSet.Tables( 0).Rows(0).Item (0).ToString

End Function

Public Shared Function GetValue(ByVal Table As String, ByVal Field
As String, ByVal Key As String, ByVal KeyField As String) As String

Dim DataSet As DataSet = GetDataSet("SEL ECT " & Field & " FROM
" & Table & " WHERE " & KeyField & " = " & Key)
If DataSet.Tables( 0).Rows.Count > 0 Then Return
DataSet.Tables( 0).Rows(0).Item (0).ToString

End Function

Public Shared Function GetID(ByVal Table As String, ByVal Key As
String, ByVal KeyField As String) As Guid

Dim DataSet As DataSet = GetDataSet("SEL ECT ID FROM " & Table
& " WHERE " & KeyField & " = " & Key)
If DataSet.Tables( 0).Rows.Count > 0 Then Return
CType(DataSet.T ables(0).Rows(0 ).Item(0), Guid)

End Function

Public Shared Function GetCount(ByVal Table As String, ByVal Key
As Guid) As Integer

Dim DataSet As DataSet = GetDataSet("SEL ECT COUNT(ID) FROM " &
Table & " WHERE ID = {" & Key.ToString & "}")
Try
Return CInt(DataSet.Ta bles(0).Rows(0) .Item(0))
Catch ex As Exception
Return 0
End Try

End Function

Public Shared Function GetCount(ByVal Table As String, ByVal
Filter As String) As Integer

Dim DataSet As DataSet = GetDataSet("SEL ECT COUNT(ID) FROM " &
Table & " WHERE " & Filter)
Try
Return CInt(DataSet.Ta bles(0).Rows(0) .Item(0))
Catch ex As Exception
Return 0
End Try

End Function

Public Shared Function GetCount(ByVal Query As String) As Integer

Dim DataSet As DataSet = GetDataSet(Quer y)
Try
Return DataSet.Tables( 0).Rows.Count()
Catch ex As Exception
Return 0
End Try

End Function

Public Shared Function GetDataSet(ByVa l Query As String) As
DataSet

Dim DataAdapter As New OleDbDataAdapte r(Query,
Global.DataSour ce)
GetDataSet = New DataSet
DataAdapter.Fil l(GetDataSet)
Return GetDataSet

End Function

#End Region

#Region "Append"

Public Shared Function Execute(ByVal Query As String) As String

Dim Connection As New OleDbConnection (Global.DataSou rce)
Connection.Open ()
Dim Command As OleDbCommand = New OleDbCommand(Qu ery,
Connection)
Try
Command.Execute NonQuery()
Catch ex As Exception
Execute = ex.Message & vbLf & vbLf & Query
End Try
Connection.Clos e()

End Function

#End Region

End Class

</code>

This is all very specific to my needs, but have a look at the
GetDataSet function, i think this is pretty much what you are after.
To create a dataset in the project all i have to do is the following
call:

Dim MyDataSet as DataSet = Data.GetDataSet ("SELECT * FROM MyTable")
Hope this helps

Blu
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6561
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
9
4416
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind the "help" button, in other words. I thought it would be os.spawnv(os.P_DETACH,...
4
3358
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to cmd.Cmd but I would also like to get the man-page-like help for classes and functions. Does anyone know how to do that? Thanks. Sarir
2
6487
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
3
3367
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With numarray, help gives unhelpful responses:
4
2638
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then type in a command line that runs the help in the correct Context from a button on each form. It all worked fine - HERE. The problem is that when I sent it out to a site, the help file was not able to be accessed because it was my path in the...
9
2249
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help for your progs? Whats the current popular approach to creating help? I am only wanting a straight help file accessible from a menu - no context sensitive stuff. TIA
8
3238
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both including search the internet for help, but the help is worthless. Any ideas?
0
2895
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
6
2882
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.