Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

cannot connect to sqlserver

I have the following that I hoped would fill a combo box with a client name. it wont connect, I wonder if its because of the connection string and the fact that the db is called Client Data.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim connetionString As String = Nothing
        Dim connection As SqlConnection
        Dim command As SqlCommand
        Dim adapter As New SqlDataAdapter()
        Dim ds As New DataSet()
        Dim i As Integer = 0
        Dim sql As String = Nothing
        connetionString = "Data Source=MAIN-PC\SQLEXPRESS;Initial Catalog=Client Data;Integrated Security=True;MultipleActiveResultSets=True"
        sql = "select * from Clients orderby;"
        connection = New SqlConnection(connetionString)
        Try
            connection.Open()
            command = New SqlCommand(sql, connection)
            adapter.SelectCommand = command
            adapter.Fill(ds)
            adapter.Dispose()
            command.Dispose()
            connection.Close()
            CBClients.DataSource = ds.Tables(0)
            CBClients.ValueMember = "ID"

            CBClients.DisplayMember = "ClientName"
        Catch ex As Exception
            MessageBox.Show("Can not open connection ! ")
        End Try
    End Sub

Open in new window


User generated image
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Your SELECT command is incomplete. Order by which field?
sql = "select * from Clients orderby;"

Or you remove the order by or you add a column:
  1. sql = "select * from Clients;"
  2. sql = "select * from Clients order by ClientName;"
Which error do you have?

BTW, your query is not valid:
sql = "select * from Clients orderby;"

Open in new window


For the test, try to use:
sql = "select * from Clients"

Open in new window

Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

Thats a surprise as I ran this in the sql query window itself:

select *
from Clients
orderby

Open in new window


anyway i simplified it to no avail ive just renamed it to try that

i f11 thru and it gets to the combo filling part then the error trapping catches it.
which database engine are you using? orderby alone is not complete for all engines I know!
what is the value of ex.Message in your error handler?
And it is ORDER BY and not ORDERBY (a space is needed).
Ive taken the order by out but it still wont connect


error messages or log of some sort:

'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'c:\users\peter\documents\visual studio 2015\Projects\MultiClientComparitor\MultiClientComparitor\bin\Debug\MultiClientComparitor.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x1ea8 has exited with code 0 (0x0).
The thread 0x1168 has exited with code 0 (0x0).
The thread 0x5f4 has exited with code 0 (0x0).
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'c:\users\peter\documents\visual studio 2015\Projects\MultiClientComparitor\MultiClientComparitor\bin\Debug\MultiClientComparitor.exe'. Symbols loaded.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Caching\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Caching.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vshost.exe' (CLR v4.0.30319: MultiClientComparitor.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Exception thrown: 'System.ArgumentException' in System.Windows.Forms.dll
just as an addition I can see the table in the server explorer tab and it does allow me to see the data in the table so I guess that means the sql server is ok for permissions and stuff.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial