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
Which error do you have?
BTW, your query is not valid:
For the test, try to use:
BTW, your query is not valid:
sql = "select * from Clients orderby;"
For the test, try to use:
sql = "select * from Clients"
ASKER
Thats a surprise as I ran this in the sql query window itself:
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.
select *
from Clients
orderby
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?
what is the value of ex.Message in your error handler?
And it is ORDER BY and not ORDERBY (a space is needed).
ASKER
Ive taken the order by out but it still wont connect
error messages or log of some sort:
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_32\msco rlib\v4.0_ 4.0.0.0__b 77a5c56193 4e089\msco rlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\assembly\GAC_M SIL\Micros oft.Visual Studio.Hos tingProces s.Utilitie s\14.0.0.0 __b03f5f7f 11d50a3a\M icrosoft.V isualStudi o.HostingP rocess.Uti lities.dll '. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Windo ws.Forms\v 4.0_4.0.0. 0__b77a5c5 61934e089\ System.Win dows.Forms .dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem\v4.0_ 4.0.0.0__b 77a5c56193 4e089\Syst em.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Drawi ng\v4.0_4. 0.0.0__b03 f5f7f11d50 a3a\System .Drawing.d ll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\assembly\GAC_M SIL\Micros oft.Visual Studio.Hos tingProces s.Utilitie s.Sync\14. 0.0.0__b03 f5f7f11d50 a3a\Micros oft.Visual Studio.Hos tingProces s.Utilitie s.Sync.dll '. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\assembly\GAC_M SIL\Micros oft.Visual Studio.Deb ugger.Runt ime\14.0.0 .0__b03f5f 7f11d50a3a \Microsoft .VisualStu dio.Debugg er.Runtime .dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'c:\users\peter\documents\ visual studio 2015\Projects\MultiClientC omparitor\ MultiClien tComparito r\bin\Debu g\MultiCli entCompari tor.vshost .exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_32\Syst em.Data\v4 .0_4.0.0.0 __b77a5c56 1934e089\S ystem.Data .dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Core\ v4.0_4.0.0 .0__b77a5c 561934e089 \System.Co re.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Deplo yment\v4.0 _4.0.0.0__ b03f5f7f11 d50a3a\Sys tem.Deploy ment.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Xml\v 4.0_4.0.0. 0__b77a5c5 61934e089\ System.Xml .dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Xml.L inq\v4.0_4 .0.0.0__b7 7a5c561934 e089\Syste m.Xml.Linq .dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Data. DataSetExt ensions\v4 .0_4.0.0.0 __b77a5c56 1934e089\S ystem.Data .DataSetEx tensions.d ll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Net.H ttp\v4.0_4 .0.0.0__b0 3f5f7f11d5 0a3a\Syste m.Net.Http .dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Mi crosoft.Vi sualBasic\ v4.0_10.0. 0.0__b03f5 f7f11d50a3 a\Microsof t.VisualBa sic.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.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'c:\users\peter\documents\ visual studio 2015\Projects\MultiClientC omparitor\ MultiClien tComparito r\bin\Debu g\MultiCli entCompari tor.exe'. Symbols loaded.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Runti me.Remotin g\v4.0_4.0 .0.0__b77a 5c561934e0 89\System. Runtime.Re moting.dll '. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Confi guration\v 4.0_4.0.0. 0__b03f5f7 f11d50a3a\ System.Con figuration .dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_32\Syst em.Transac tions\v4.0 _4.0.0.0__ b77a5c5619 34e089\Sys tem.Transa ctions.dll '. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_32\Syst em.Enterpr iseService s\v4.0_4.0 .0.0__b03f 5f7f11d50a 3a\System. Enterprise Services.d ll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_32\Syst em.Enterpr iseService s\v4.0_4.0 .0.0__b03f 5f7f11d50a 3a\System. Enterprise Services.W rapper.dll '. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Runti me.Caching \v4.0_4.0. 0.0__b03f5 f7f11d50a3 a\System.R untime.Cac hing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MultiClientComparitor.vsh ost.exe' (CLR v4.0.30319: MultiClientComparitor.vsho st.exe): Loaded 'C:\Windows\Microsoft.Net\ assembly\G AC_MSIL\Sy stem.Numer ics\v4.0_4 .0.0.0__b7 7a5c561934 e089\Syste m.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
error messages or log of some sort:
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
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.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
'MultiClientComparitor.vsh
Exception thrown: 'System.ArgumentException'
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sql = "select * from Clients orderby;"
Or you remove the order by or you add a column: