Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 February 7th, 2005, 08:19 PM
Registered User
 
Join Date: Feb 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Server with ADO.NET

Hi everyone,

This error what i get when i run the code below
 "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"

after this error message i chose "breake" then the cursor indicates to this line with green line

 objConnection.open()

is this error from dll files or sql setting or ...
with using vb.net & sql server 2000
-----------------------------
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim objConnection As OleDbConnection = New _
    OleDbConnection("Provider=SQLOLEDB.1" & _
    "Data Source =HOMEPC;Initial Catalog=pubs;" & _
"Integradted Security=SSPI;")
    Dim objDataAdapter As New OleDbDataAdapter
    Dim objDataSet As DataSet = New DataSet


 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Set the SelectCommand properties...
        objDataAdapter.SelectCommand = New OleDbCommand
        objDataAdapter.SelectCommand.Connection = objConnection
        objDataAdapter.SelectCommand.CommandText = _
            "SELECT au_lname, au_fname, title, price " & _
            "FROM authors " & _
            "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
            "JOIN titles ON titleauthor.title_id = titles.title_id " & _
            "ORDER BY au_lname, au_fname"
        objDataAdapter.SelectCommand.CommandType = CommandType.Text
        objConnection.Open()
        objDataAdapter.SelectCommand = New OleDbCommand
        objDataAdapter.SelectCommand.Connection = objConnection
        objDataAdapter.SelectCommand.CommandText = _
        "SELECT au_lname, au_fname; title, price " & _
        "JOIN titleauthor ON authors.au_id = titlauthor.au_id " & _
        "JOIN titles ON titleauthor.title_id = titles.title_id " & _
        "ORDER BY au_lname,au_fname"
        objDataAdapter.SelectCommand.CommandType = CommandType.Text
        objDataAdapter.SelectCommand.ExecuteNonQuery()
        objDataAdapter.Fill(objDataSet, "authors")
        objConnection.Close()
        objDataAdapter = Nothing
        objConnection = Nothing
        grdAuthorTitles.DataSource = objDataSet
        grdAuthorTitles.DataMember = "authors"
-------------------------------------------------------




 
Old February 8th, 2005, 09:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Why are you using OleDB with SQL Server?


 
Old February 8th, 2005, 09:29 AM
Registered User
 
Join Date: Feb 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for reply
Why i use OleDb with SQl really i dont know
but this code is in the beginning vb.net book


 
Old February 8th, 2005, 09:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try using Imports System.Data.SqlClient and changing all OleDB to SQL in your code.

Proper connection string.
http://www.connectionstrings.com/

 
Old February 8th, 2005, 09:19 PM
Registered User
 
Join Date: Feb 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again,

With this declaration

Dim myConnection As SqlConnection = New _
        SqlConnection("server=HOMEPC;database=pubs;Integra ted Security=SSPI;")
    Dim myDataAdapter As New SqlDataAdapter
    Dim myDataSet As DataSet = New DataSet


 AND THIS IS THE ERROR MSG



An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.



When i using sql rather than OleDb,in the OleDb the cursor indicate o
objConnnection.open ()

but with sql the cursor indicate to

myDataAdapter.SelectCommand.ExecuteNonQuery()









Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO.NET connectivity problem with SQL Server !!! virajp ADO.NET 2 December 5th, 2005 11:51 PM
ADO.Net slower than SQL Server Query Analyzer s5g5r ADO.NET 1 January 26th, 2005 09:49 PM
how can i link to sql-server with ado.net[B)] zjxgjp ADO.NET 1 December 25th, 2004 09:50 AM
Ado.net performance question (SQL server vs OleDB spamp ADO.NET 1 August 2nd, 2004 10:37 AM
MSDE and SQL CE (using VB.NET and ADO.NET) LEGS ADO.NET 0 July 12th, 2003 11:27 AM





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