Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SqlDataReader Exception

Status
Not open for further replies.

jimbledon

Technical User
Dec 27, 2004
22
GB
Hi all,

I'm trying to build a small mobile app that populates a combo box from a sql server located on a server.

The error returned is a 'SQL Exception' and the code bombs out on the connection.open() statement.

Code:
Imports System
Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient.SqlConnection
Imports System.Data.SqlClient.SqlCommand
Imports System.Data.SqlClient.SqlException
Imports System.Drawing
Imports System.Data.SqlClient.SqlDataReader

Try
            Dim strSelectCustomers As String = "SELECT CustId, (CustSName + ' ' + CustFName) as [CustName] FROM TblCustTable"

            Dim strConnString As String = "data source=192.168.1.103;database=Project;integrated security=SSPI;user ID=IUSR_JAMES;Password=password"
            ' Using the connection object
            Dim connProject As New SqlClient.SqlConnection
            connProject.ConnectionString = strConnString

            Dim cmdCustomers As New SqlCommand(strSelectCustomers, connProject)
            Dim drCustomers As SqlDataReader
            connProject.Open()
            drCustomers = cmdCustomers.ExecuteReader()

            Dim StrState As String

            StrState = connProject.State.ToString()
            TextBox1.Text = StrState.ToString()



            MsgBox("connected and datareader populated")


            connProject.Close()


        Catch excNull As Exception
           
            MsgBox("1: " & excNull.Message)
            'Console.WriteLine(excNull.InnerException)
            StatusBar1.Text = "1: " & excNull.GetBaseException.Message
        Catch excPaul As NullReferenceException

            MsgBox("2: " & excPaul.Message.GetHashCode)
            'Console.WriteLine(excNull.InnerException)
            StatusBar1.Text = excPaul.Message.GetHashCode

        End Try

The code works when run on a windows application but it fails to connect on a mobile application.

Can anybody spot where i have gone wrong as i have been staring at this all day!!

Many Thanks
 
for integrated security setting.... when set to sspi or true the current windows account credentials are used for authentication not the login and pwd provided....set this to false if you intend not to use windows authentication.

Not sure if this is exactly the issue, but look at the help document for SqlConnection.ConnectionString Property for more information on creating a connection string. It provides a table for all the keyword values in the connection string.

Sam
 
Hi,

Thanks for the reply

Changed the connection to this, it still bombs out but it is happening quicker now

Code:
Dim strConnString As String = "data source=192.168.1.103;Initial Catalog=Project;Integrated Security=SSPI"

Regards

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top