Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
| Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics 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
  #1 (permalink)  
Old November 30th, 2006, 08:01 AM
Authorized User
 
Join Date: Nov 2006
Location: lagos, Lagos, Nigeria.
Posts: 22
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to darkestangel1980
Default VB exception handling problems

Hi
I am working on a little project using the new VB.net 2005 I keep getting this error

"An error occur. Error Number: 5 Description: Format of the initialization string does not conform to specification starting at index 0. Source: System.Data"


"An error occured. Error Number: 91 Description: object reference not set an instance of an object. Source: MainApp"


Please i need your help.

Thanks


  #2 (permalink)  
Old November 30th, 2006, 08:10 AM
Authorized User
 
Join Date: Nov 2006
Location: , , USA.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

Judging by the fact that the namespace "system.data" generated the error you are having problems connecting to a database. In order for any of us to assist you further you will need to post the portion of the code that generated the error. Please remember to use the "#" button before pasting your code in as it will leave the code sample properly formatted.

Thanks!



Best Regards,
Earl Francis
  #3 (permalink)  
Old November 30th, 2006, 08:19 AM
Authorized User
 
Join Date: Nov 2006
Location: lagos, Lagos, Nigeria.
Posts: 22
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to darkestangel1980
Default

I wanted to know where area of the code should post you because my codes is much.

thanks
  #4 (permalink)  
Old November 30th, 2006, 08:43 AM
Authorized User
 
Join Date: Nov 2006
Location: , , USA.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

Only the section of the code that is generating the error is needed. You are probably creating connection and command objects, so just paste that code as a reply.



Best Regards,
Earl Francis
  #5 (permalink)  
Old November 30th, 2006, 10:58 AM
Authorized User
 
Join Date: Nov 2006
Location: lagos, Lagos, Nigeria.
Posts: 22
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to darkestangel1980
Default

Imports System.Data
Imports System.Data.SqlClient
Public Class clsDatabase
    Function PopulateDataSetTable(ByVal strConnection As String, ByVal strTableName As String, ByVal strSQLorStoredProc As String, ByVal blnStoredProcedure As Boolean, ByRef dsDataSet As DataSet) As DataSet

        Try
            Dim sqlConn As New SqlClient.SqlConnection(strConnection)
            sqlConn.Open()
            Dim adapterProducts As New SqlClient.SqlDataAdapter()
            adapterProducts.TableMappings.Add("Table", strTableName)
            Dim cmdTable As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQLorStoredProc, sqlConn)
            'run stored procedure or SQL statement accordingly
            If blnStoredProcedure Then
                cmdTable.CommandType = CommandType.StoredProcedure
            Else
                cmdTable.CommandType = CommandType.Text
            End If
            adapterProducts.SelectCommand = cmdTable
            'fill the data set with the table information as specified in
            'the stored procedure or from the results of the SQL statement
            adapterProducts.Fill(dsDataSet)
            sqlConn.Close()
            Return dsDataSet
        Catch
            'error handling goes here
            UnhandledExceptionHandler()
        End Try
    End Function



Public Class BaseSearchform
    Inherits System.Windows.Forms.Form

    Protected Const PROD = "Products"
    Protected Const SUPP = "Suppliers"
    Protected Const CONN = "user id="";password=; initial " & "catalog=NorthwindSQL;server=local"

    Protected dsData As DataSet
    Protected dsResults As DataSet
    Protected adapterResults As New SqlClient.SqlDataAdapter()


    'Sub UnhandledExeceptionHandler()
    ' MsgBox("An error occurred. Error Number: " & Err.Number & "Description: " & Err.Description & " Source:" & Err.Source)
    'End Sub

    Sub AddSearchMethod()
        Try
            If cboSearchMethod.Items.Count = 0 Then
                cboSearchMethod.Items.Add(PROD)
                cboSearchMethod.Items.Add(SUPP)
            End If
        Catch ex As Exception
            UnhandledExceptionHandler()
        End Try
    End Sub
  #6 (permalink)  
Old November 30th, 2006, 11:08 AM
Authorized User
 
Join Date: Nov 2006
Location: , , USA.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

I was able to duplicate your error in a test environment on my computer.

It looks like you need to designate a user and a password in your connection string.

You have:

Protected Const CONN = "user id="";password=; initial " & "catalog=NorthwindSQL;server=local"

It should read:

Protected Const CONN = "user id=" & YourUserNameHere & ";password=" & YourPassWordHere & "; initial " & "catalog=NorthwindSQL;server=local"

You need to either hard code a user and a password (not generally a good idea from a security standpoint), or present a login screen and get the information that way.

I hope this helps, and good luck!



Best Regards,
Earl Francis
  #7 (permalink)  
Old November 30th, 2006, 11:23 AM
Authorized User
 
Join Date: Nov 2006
Location: lagos, Lagos, Nigeria.
Posts: 22
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to darkestangel1980
Default

Thanks but i used windows authenication to login to my sql server. i dont use a password and the username field is always blank.

Please can you kindly tell me how i can put it.
thanks

  #8 (permalink)  
Old November 30th, 2006, 11:31 AM
Authorized User
 
Join Date: Nov 2006
Location: , , USA.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

To use Windows authentication in your connection string, replace the "user id=xx;password=xx" part with "Integrated Security=SSPI;"

Example:
Protected Const CONN = "Integrated Security=SSPI; initial " & "catalog=NorthwindSQL;server=local"






Best Regards,
Earl Francis
  #9 (permalink)  
Old December 1st, 2006, 09:47 AM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Lagos, Lagos, Nigeria.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dababy Send a message via Yahoo to dababy
Default

Thanks a lot but i just got this recent error.

"An error occured. Error Number: 5 Description: An error has occurred while establishing a connection to the server. When connectiong to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider:Name Pipes Provider, error 40- Could not open a connection to SQL Server) Source:.net SqlClient Data Provider"

This is how i did my connection i don't know whether that is the cause.

"Protected Const CONN = "Integrated Security=SSPI; initial " & "catalog=NorthwindSQL;server=local" & "user id=xx;password=xx;"

Also i am not using SQL2005 i am using SQL2000.

thanks

thats
  #10 (permalink)  
Old January 17th, 2007, 12:43 PM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default

Are NamedPipes and TCP/IP connections (remote connections) allowed on the server you are attempting to connect to?

Make sure they are, then everything should work fine. (I've been dealing with this one a bunch!)

Karen





Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception Handling NewTitle2007 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 6 August 8th, 2007 04:03 AM
exception handling jay schumacher VB.NET 2002/2003 Basics 1 April 14th, 2006 08:40 AM
Exception handling aldwinenriquez General .NET 0 August 17th, 2005 06:13 PM





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