473,405 Members | 2,445 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,405 software developers and data experts.

command.CommandTimeout

Can someone please help me? I have class for database connection and I need set command.commandTimeout. How can I do that?

Code:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Data
  3. Public Class Db
  4.     Private Shared _ConnString As String = ""
  5.     Private Shared _Connection As SqlConnection
  6.  
  7.     Public Shared Sub SetConnectionString(ByVal connString As String)
  8.         _ConnString = connString
  9.     End Sub
  10.  
  11.     Public Shared Function GetReader(ByVal sqlStatement As String, ByVal params() As Object) As SqlDataReader
  12.         OpenConnection()
  13.         Dim command As SqlCommand
  14.         command = FillParams(sqlStatement, params)
  15.         Return command.ExecuteReader(CommandBehavior.CloseConnection)
  16.     End Function
  17.  
  18.     Public Shared Function GetDataSet(ByVal sqlStatement As String) As DataSet
  19.         Dim retDs As New DataSet
  20.         OpenConnection()
  21.         Dim ad As New SqlDataAdapter(sqlStatement, _Connection)
  22.         ad.Fill(retDs)
  23.         _Connection.Close()
  24.         Return retDs
  25.     End Function
  26.  
  27.     Public Shared Function Exec(ByVal sqlStatement As String, ByVal params() As Object, ByVal maOutput As Boolean) As ArrayList
  28.         Dim ret As ArrayList = New ArrayList
  29.         OpenConnection()
  30.         Dim command As SqlCommand
  31.  
  32.         command = FillParams(sqlStatement, params)
  33.         command.ExecuteNonQuery()
  34.         For Each p As SqlParameter In command.Parameters
  35.             If p.Direction = ParameterDirection.InputOutput Or p.Direction = ParameterDirection.Output Then
  36.         Try
  37.           ret.Add(p.Value)
  38.         Catch : End Try
  39.       End If
  40.         Next
  41.         Return ret
  42.     End Function
  43.  
  44.     Public Shared Function execCom(ByVal sqlStatement As String, ByVal params() As Object) As Int32
  45.         OpenConnection()
  46.         Dim command As SqlCommand
  47.  
  48.         command = FillParams(sqlStatement, params)
  49.  
  50.         Return command.ExecuteNonQuery()
  51.     End Function
  52.  
  53.     Private Shared Function FillParams(ByVal sqlStatement As String, ByVal params() As Object) As SqlCommand
  54.         Dim command As New SqlCommand(sqlStatement, _Connection)
  55.  
  56.  
  57.         If Not params Is Nothing Then
  58.             Dim i As Int16
  59.             For i = 0 To params.Length - 1
  60.                 command.Parameters.Add(CType(params(i), SqlParameter))
  61.             Next
  62.         End If
  63.         Return command
  64.     End Function
  65.  
  66.     Private Shared Sub OpenConnection()
  67.         If _Connection Is Nothing Then
  68.             _Connection = New SqlConnection(_ConnString)
  69.         End If
  70.  
  71.         If Not _Connection.State = ConnectionState.Open Then
  72.             _Connection.Open()
  73.         Else
  74.             _Connection.Close()
  75.             _Connection.Open()
  76.         End If
  77.     End Sub
  78.  
  79.  
  80. End Class
Sep 3 '07 #1
0 1484

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

Similar topics

4
by: Cath B | last post by:
I am pretty sure I am getting a command timeout when execute a SQL procedure that has an output parameter. The code below is in an asp page that is called using RSGetASPObject. I want to be able...
2
by: Tahir Khan | last post by:
I am running into a command time out error. I have to retrieve a lot of date thru a complex query. For some reason, I can't change the commandtimeout to more then 30 secs. And yes I have...
1
by: Sandie Towers | last post by:
We use a number of similar databases and frequently create a new database using a backup restore of another similar database. We try to keep changes between databases in _Additional tables - like...
1
by: Craig Thompson | last post by:
Does anyone know of a way to set the Command TimeOut when you are using the DAAB? Am I going to have to modify DAAB code to accept a new parameter?... BTW, setting the connection timeout in the...
12
by: Piotrek | last post by:
HI all. In my web site I have some ObjetDataSource. Its business object property is set to my dataset I created in dataset designer (this dataset has table adapter). My question is: how can I...
2
by: Mangler | last post by:
I a running a SP and calling it through ASP. I keep getting this error: Parameter object is improperly defined. Inconsistent or incomplete information was provided. I think I have the...
2
by: John Kotuby | last post by:
Hi all, I have set up a page with a Repeater and a SQLDatasource control, the data control suggested by online Help for use with the Repeater. I am getting Timeout Expired after 30 seconds. I...
5
by: downwitch | last post by:
I have the strangest error, and wonder if anyone else has seen it. I'm using ADODB to return a set of SQL Server 2005 records via ODBC. If I open the recordset this way With cmd .CommandType =...
0
by: czerwww | last post by:
Can someone please help me? I have class for database connection and I need set command.commandTimeout. How can I do that? Code: Imports System.Data.SqlClient Imports System.Data Public Class...
1
by: Leon Mayne | last post by:
Hello, I had a chunk of code that would execute a stored proc to migrate data between two systems (takes a few minutes) and then performs some data manipulation on the migrated data. This was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.