May 2005 - Posts
Download url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2005/11/08/podcast-2.aspx
Pablo Castro
Article on Asynchronous ADO.NET.
Managed Data Access
Please Buy a copy of our book!
Scott Guthrie
IIS7 with Scott Guthrie
Code Samples:
BeginExecuteNonQuery
Dim strSql As String
Dim strCn As String = Me.gstrAsyncString
Dim iResult As IAsyncResult
sqlCm = New SqlCommand()
sqlCn = New SqlConnection(strCn)
sqlCn.Open()
sqlCm.Connection = sqlCn
sqlCm.CommandType = CommandType.Text
strSql = "insert into tblAsyncExecuteNonQuery ( ClientDateEntered) values ('" & DateTime.Now.ToString() & "')"
sqlCm.CommandText = strSql
Me.gdtStart = GetTickCount()
iResult = sqlCm.BeginExecuteNonQuery(New System.AsyncCallback(AddressOf ExecuteNonQueryCallback), sqlCm)
Private Sub ExecuteNonQueryCallback(ByVal iRes As IAsyncResult)
Dim sqlCm As SqlCommand = CType(iRes.AsyncState, SqlCommand)
Try
sqlCm.EndExecuteNonQuery(iRes)
Me.gdtEnd = GetTickCount()
Dim timeDsplay As New DisplayTimeDelegate(AddressOf DisplayTime)
Me.Invoke(timeDsplay)
Catch sqlExc As SqlException
'Perform some type of operation to notify someone that an error has occurred.
'If an exception occurs, show it to the user.
Finally
If sqlCn.State <> ConnectionState.Closed Then
sqlCn.Close()
End If
sqlCn.Dispose()
sqlCn = Nothing
sqlCm.Dispose()
sqlCm = Nothing
End Try
End Sub
BeginExecuteReader
Dim strSql As String
Dim strCn As String = gstrAsyncString
Dim iResult As IAsyncResult
sqlCm = New SqlCommand()
sqlCn = New SqlConnection(strCn)
sqlCn.Open()
sqlCm.Connection = sqlCn
sqlCm.CommandType = CommandType.Text
strSql = "select count(*) from tblAsyncExecuteNonQuery"
sqlCm.CommandText = strSql
Me.gdtStart = GetTickCount()
iResult = sqlCm.BeginExecuteReader(New System.AsyncCallback(AddressOf ExecuteDataReaderCallback), sqlCm, CommandBehavior.Default)
Private Sub ExecuteDataReaderCallback(ByVal iRes As IAsyncResult)
Dim sqlDr As SqlDataReader
Dim sqlCm As SqlCommand = CType(iRes.AsyncState, SqlCommand)
Try
sqlDr = sqlCm.EndExecuteReader(iRes)
Me.gdtEnd = GetTickCount()
sqlDr.Read()
Me.giNum = Convert.ToInt32(sqlDr(0))
Dim cntDsplay As New DisplayCountDelegate(AddressOf DisplayCount)
Me.Invoke(cntDsplay)
sqlDr.Close()
sqlDr.Dispose()
sqlDr = Nothing
Catch sqlExc As SqlException
'Perform some type of operation to notify someone that an error has occurred.
'If an exception occurs, show it to the user.
Finally
If sqlCn.State <> ConnectionState.Closed Then
sqlCn.Close()
End If
sqlCn.Dispose()
sqlCn = Nothing
sqlCm.Dispose()
sqlCm = Nothing
End Try
SqlConnectionStringBuilder
Dim sqlCn As New SqlConnection()
Dim scsbObj As New SqlClient.SqlConnectionStringBuilder(Me.gstrSyncString)
Try
scsbObj.Password = Me.txtPassword.Text
SqlConnection.ChangePassword(scsbObj.ConnectionString, Me.txtNewPassword.Text)
scsbObj.Password = Me.txtNewPassword.Text
sqlCn.ConnectionString = scsbObj.ConnectionString
sqlCn.Open()
Me.gstrSyncString = scsbObj.ConnectionString
MsgBox("Succesful logon with a new password.")
Catch sqlEx As SqlException
'Do something with this error.
MsgBox("Error: " & sqlEx.Message.ToString())
Finally
If sqlCn.State <> ConnectionState.Closed Then
sqlCn.Close()
End If
sqlCn.Dispose()
sqlCn = Nothing
End Try
DataTypes:
Dim i As Integer
Dim strSql As String = "select * from tblTest where 1=2"
Dim scsbObj As New SqlConnectionStringBuilder(Me.gstrSyncString)
Dim sqlCn As New SqlConnection(scsbObj.ConnectionString)
Dim sqlCm As New SqlCommand(strSql, sqlCn)
Dim sqlDr As SqlDataReader
Dim dtData As DataTable
Try
sqlCn.Open()
sqlDr = sqlCm.ExecuteReader(CommandBehavior.SchemaOnly)
dtData = sqlDr.GetSchemaTable()
Me.dgvColumns.DataSource = dtData
Me.dgvColumns.Visible = True
' sqlDr.Read()
For i = 0 To (sqlDr.FieldCount - 1)
MsgBox(sqlDr.GetName(i) + vbCrLf + "SqlType: " + _
Convert.ToString(sqlDr.GetProviderSpecificFieldType(i)) + vbCrLf + _
"Database Type: " + Convert.ToString(sqlDr.GetDataTypeName(i)) + vbCrLf + _
".NET Type: " + Convert.ToString(sqlDr.GetFieldType(i)) + vbCrLf)
Next
If Not (sqlDr.IsClosed = True) Then
sqlDr.Close()
End If
sqlDr.Dispose()
sqlDr = Nothing
Catch sqlExc As SqlException
MsgBox("Error: " & sqlExc.Message.ToString())
Finally
sqlCm.Dispose()
sqlCm = Nothing
If sqlCn.State <> ConnectionState.Closed Then
sqlCn.Close()
End If
sqlCn.Dispose()
sqlCn = Nothing
End Try
End Sub
Guy Barrette reminded me that I had not posted this yet.
I have written some really good SqlCLR objects that I have been doing for a demo. Having updated these CLR objects to run on the April CTP, I am now really glad that the Sql Server/ADO.NET Team removed the System.Data.SqlServer namespace and plugged all of that code into the System.Data.SqlClient namespace. By doing this, my code now looks and smells like any other data access code that I would have in a standard data access layer in other parts of my application. I was skeptical at the time, but I think that the change was a good move.
Wally
Greg Low has put together and is doing the Sql Down Under podcast. I met Greg earlier this week in Redmond. Greg is very knowledgeable with .NET and Sql Server. I was very impressed with him. This podcast, is something that I will be listening to.
http://www.sqldownunder.com/
Wally
http://www.eweek.com/article2/0,1759,1819419,00.asp Mainsoft Corp. Tuesday announced a program and a new tool for Visual Studio .Net developers to use their familiar tool set to write applications for Linux.
The San Jose, Calif., company announced its Visual Studio .Net for Linux Developer Program as well as its new Visual MainWin for J2EE (Java 2 Enterprise Edition) Developer Edition tool, code-named Grasshopper.
From the article, It looks like there will be two versions. The free version works with Apache/Tomcat. The for-pay version works with several J2EE platforms.
Wally
http://news.com.com/Apple+allegedly+explores+using+Intel+chips/2100-1042_3-5716539.html?tag=nefd.top
Apple Computer has been in talks that could lead to a decision soon to use Intel chips in its Macintosh line, according to a report published Monday.
The Wall Street Journal, citing two industry executives with knowledge of recent discussions between the companies, reported that Apple will agree to use Intel chips.
Neither company would confirm the report, and an Apple representative told the Journal that the information should be characterized as "rumor and speculation."
Wally
PS. Wow, what a cool #600 entry. Personally, my guess is that Apple might use some support chips.
I have been working on some components that require signing. One of the things that frustrated me back during .NET 1.x beta was that the option to automagically create a keyfile was removed after beta 2. The feedback that I heard was that security is important and the ability to just randomly create a keyfile was not good practice, therefore the ability to create the keyfile was removed. Well, I have been dinking back around with COM+ in Whidbey. With COM+, you have to create a keyfile. Well, the ability to create and use a key has been put back into the IDE as of Beta 2, which I think is great news. You select your project and then its properties. There is a tab label signing. With that, you can either create a new keyfile or use an exisiting one. One side genefit of this is that it appears there is no need to specify the assebly's keyfile in the attributes for the assembly. I think that this is an improvement as I always seemed to have problems with getting the directory correct in Everrett.
Wally
Ok, so by now, it is obvious that I have started working on some Windows
Services written in .NET. :-)
As I remember, in .NET Everrett, if I manually entered the process and
service installer into the the service's install class, the process and service
installer would not display in the design surface. Well, in Whidbey's
VS.NET IDE, the process and service installer are displayed on the design
surface after I manually entered them. Sweet.
Wally
The install routine for a Windows Service will allow you to default the
service to one of four user ids.
- LocalService.
- LocalSystem.
- NetworkService.
- User.
These values are provided by the enum System.ServiceProcess.ServiceAccount.
Typically, when I write a Windows Service, I will either run it as the
LocalSystem or as a User. If you run as the LocalSystem, don't forget to
set the Username and Password properties of your ServiceProcessInstaller object
to null.
Wally
When you startup your Windows Services that are written in .NET, you can
specify three startup modes:
- Automatic. When the system starts up, the service will startup as if
it is set to Automatic in the Services applet.
- Manual. When the system starts up, the service will startup as
if it is set to Manual in the Services applet.
- Disabled. When the system starts up, the service will
not startup as if the service is set in the Disabled mode in the Services
applet.
These modes are provided by the enum System.ServiceProcess.ServiceStartMode.
Wally
More Posts
Next page »