Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Go Back  Xtreme Visual Basic Talk > > > Starting to hate SQL, spot the bug.


Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2012, 09:48 AM
bigmonmulgrew bigmonmulgrew is offline
Regular
 
Join Date: Feb 2008
Posts: 73
Default Starting to hate SQL, spot the bug.


I'm just getting started learning to (or trying to ) access SQL databses with VB.
I havent gotten very far.

I've been following the guide here

I've followed the guide to the letter and been over it a couple of times and I keep getting the same error
Code:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. 
The server was not found or was not accessible. 
Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
All I've changed is the path as mentioned in the guide.

I'm using VB express 2010 and SQL server express 2008

Any pointers on where I'm going wrong would be much appreciated

I've included my code below, it should be pretty much the same as the code on the guide but just in case....
Code:
Imports System.Data.SqlClient
Public Class Form1

    'at program startup, set the control properties
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Text = "Add to DB"
        Button2.Text = "Show DB"
        TextBox2.Multiline = True
    End Sub

    'write a record to the database table
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sqCon As New SqlClient.SqlConnection("Server=.\SQLExpress;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyTestDB.mdf;Database=MyTestDB; Trusted_Connection=Yes;")
        Dim sqCmd As New SqlClient.SqlCommand

        sqCmd.Connection = sqCon            'create the DB connection
        sqCmd.CommandText = "INSERT INTO [MyTestDB].[dbo].[tblTest] VALUES ('" & TextBox1.Text & "')"
        sqCon.Open()                        'open the connection
        sqCmd.ExecuteNonQuery()             'execute the SQL command
        sqCon.Close()                       'close the connection
    End Sub

    'read and display all records from the database table
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sqCon As New SqlClient.SqlConnection("Server=.\SQLExpress;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyTestDB.mdf;Database=MyTestDB; Trusted_Connection=Yes;")
        Dim sqCmd As New SqlClient.SqlCommand
        Dim sdrRow As SqlClient.SqlDataReader

        'define the DB connection and search string
        sqCmd.Connection = sqCon
        sqCmd.CommandText = "SELECT * FROM tblTest"

        'open the DB connection
        sqCon.Open()                        'open the DB connection
        sdrRow = sqCmd.ExecuteReader()      'read the entire table

        'extract and display each field
        TextBox2.Text = ""                  'clear the text box
        Do While sdrRow.Read()
            TextBox2.Text = TextBox2.Text & sdrRow.GetValue(0) & vbTab     'get the primary key
            TextBox2.Text = TextBox2.Text & sdrRow.GetValue(1) & vbCrLf    'get the string
        Loop

        'close up and return
        sdrRow.Close()
        sqCon.Close()

    End Sub
End Class
__________________
Currently Running VB Express 2010, running on Windows 7 home premium x64
System: Gigabyte GA-MA790FX-DS5, Athlon X2 5600+, Corsair 2GB matched pair 800mhz 4-4-4-12 (epp), XFX Geforce 8600GTS 256MB, Raptor 74GB SATA, Corsair HX 630W
My Blog:http://foreverythingit.co.uk/blog
Reply With Quote
  #2  
Old 02-07-2012, 11:50 AM
bigmonmulgrew bigmonmulgrew is offline
Regular
 
Join Date: Feb 2008
Posts: 73
Default

please ignore I was being stupid there was a typo
MSSQLSERVER should have been MSSQLEXPRESS
__________________
Currently Running VB Express 2010, running on Windows 7 home premium x64
System: Gigabyte GA-MA790FX-DS5, Athlon X2 5600+, Corsair 2GB matched pair 800mhz 4-4-4-12 (epp), XFX Geforce 8600GTS 256MB, Raptor 74GB SATA, Corsair HX 630W
My Blog:http://foreverythingit.co.uk/blog
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug. Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
 
Starting to hate SQL, spot the bug.
Starting to hate SQL, spot the bug.
 
-->