Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 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 April 23rd, 2004, 12:44 PM
Authorized User
Join Date: Mar 2004
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB.Net to SQL Server 2000

Hi, i have SQL Server 200 desktop engine installed on my machine. and i tried to connect to the Northwind database that comes with sql server 2000 using VB.Net. I am getting following error.
c:\inetpub\wwwroot\SQLserver_conn\WebForm1.aspx.vb (26):
Declaration expected.
Declaration expected
Type 'SqlConnection' is not defined.
Type 'SqlCommand' is not defined.

so i think i am having problem with Import System.Data and Import System.Data.SqlClient

My code is as follow:
Import System.Data
Import System.Data.SqlClient

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents dgNameList As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim strConnection As String = "server=(local)\NARESH-SIR; database=Northwind; integrated security = true;"
        Dim objConnection As New SqlConnection(strConnection)
        Dim strSQL As String = "Select FirstName, LastName, Country from Employees"
        Dim objCommand As New SqlCommand(strSQL, objConnection)
        dgNameList.DataSource = objCommand.ExecuteReader()

    End Sub

Can anyone help me please.

Old April 23rd, 2004, 01:47 PM
Authorized User
Join Date: Mar 2004
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts

I am sory, i am having problem with the connection string. connection string doesn't seem to work

Old April 23rd, 2004, 02:01 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Your imports statements don't look right. They should be like this:

Imports System.Data
Imports System.Data.SqlClient

Check out http://www.connectionstrings.com for connection string options.
Old April 23rd, 2004, 07:02 PM
Authorized User
Join Date: Mar 2004
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts

hi i used this connection string:
Dim strConnection As String = "Server=NARESH-SIR\Naresh;Database=Northwind;Trusted_Connection=T rue;".
I get the following error
 System.Data.SqlClient.SqlException: SQL Server does not exist or access denied
what i have is i have installed XP on my machine. and when i installed SQL server 2000, i just didn't put password because i used the windows authentication. so when i log into sql server 2000, i don't have to put any user name and password. i can just work on database. so i got cunfused should i use trusted_connection or standard security. i tried both but didn't seem to work

thanks for help
Old April 26th, 2004, 08:55 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts

You have installed SQL Server as a named instance on your box? If not- the server name should just be the name of the machine. I don't understand why your using NARESH-SIR\Naresh

Set Trusted Connection to TRUE and then you need to give rights to the user accessing the database- which isn't you. It's the proccess .NET runs under.. which I think is ASPNET .. but you should check your machine to be sure.

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee

Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to SQL server 2000 with VB 2005 Express ericgelders Visual Basic 2005 Basics 0 February 20th, 2007 06:15 PM
Retriving Binay Image From SQL Server 2000 In VB 6 Ammar110 VB Databases Basics 1 June 22nd, 2006 03:09 PM
Beginning VB with SQL Server 2000 JohnAlex Pro VB Databases 2 June 29th, 2004 04:20 PM
Visual Basic .NET and SQL Server 2000 rayap All Other Wrox Books 3 May 31st, 2004 09:32 AM
VB Net and SQL Server 2000 hdmdev Wrox Book Feedback 1 July 22nd, 2003 04:55 PM

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