Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2010, 06:19 AM
Registered User
 
Join Date: Jan 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default asp.net 2.0 professional listing 6

Hi, In asp.Net 2.0 professional, in chapter 12 listing 6 we introduced tranaction
I have difficulty to see where the error is
I apprechiate help.

This is the error message:
ExecuteReader requires that the command has a transaction when the connection attributed to the command were in pending local transaction.
The property Transaction of the command was not initialize

The beginning ofthe listing up to the error.:

[cod]
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.SqlClient.SqlTransaction" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System" %>

<script runat="Server">
Sub btnBulkCopy_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnBulkCopy.Click

Dim ShajarConString As String
Dim NorthWindConString As String
Dim ShajarCon As SqlConnection = New SqlConnection()
Dim NorthwindCon As SqlConnection = New SqlConnection()

Dim ShajarCom As SqlCommand = New SqlCommand()
Dim ShajarReader As SqlDataReader

ShajarConString = _
ConfigurationManager.ConnectionStrings("DSN_Shajar ").ConnectionString
NorthWindConString = _
ConfigurationManager.ConnectionStrings("DSN_Northw ind").ConnectionString

ShajarCon.ConnectionString = ShajarConString
ShajarCom.Connection = ShajarCon
ShajarCom.CommandText = "SELECT ID, First_Name, Last_Name, " & _
"'Shajar' as Source FROM MailingList_Temp "
ShajarCom.CommandType = CommandType.Text

ShajarCom.Connection.Open()

Dim Transaction As SqlTransaction
Transaction = ShajarCom.Connection.BeginTransaction()

Dim NorthWindBulkOp As SqlBulkCopy
NorthWindBulkOp = New SqlBulkCopy(New SqlConnection(NorthWindConString), _
SqlBulkCopyOptions.Default, _
Transaction)

NorthWindBulkOp.DestinationTableName = "Employees"
NorthWindBulkOp.ColumnMappings.Add("Id", "EmployeeID")
NorthWindBulkOp.ColumnMappings.Add("First_Name", "FirstName")
NorthWindBulkOp.ColumnMappings.Add("Last_Name", "LastName")

Dim JobTitleColMap As SqlBulkCopyColumnMapping
JobTitleColMap = New SqlBulkCopyColumnMapping("Source", "Title")

NorthWindBulkOp.ColumnMappings.Add(JobTitleColMap)
NorthWindBulkOp.BulkCopyTimeout = 500000000

AddHandler NorthWindBulkOp.SqlRowsCopied, _
New SqlRowsCopiedEventHandler(AddressOf OnSqlRowsCopied)

NorthWindBulkOp.NotifyAfter = 1000

ShajarReader = ShajarCom.ExecuteReader()
[/code]

Last edited by dovk179; January 25th, 2010 at 06:21 AM.. Reason: missed the [/code]





Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net professional benjii82 BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 October 30th, 2009 05:42 PM
ASP.NET Help: Directory Listing Deanied skhan ASP.NET 1.0 and 1.1 Basics 0 July 14th, 2009 02:25 PM
Professional ASP.NET davem1958 All Other Wrox Books 0 June 11th, 2003 10:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.