-
Jun 4th, 2010, 04:45 PM
#1
Thread Starter
New Member
SQL Connection Error
Trying to connect to my SQL database... Receiving this error:
Non-negative number required.
Parameter name: count
It points to cn.Open()
No idea how to fix this, any ideas?
-
Jun 4th, 2010, 06:09 PM
#2
Re: SQL Connection Error
it might be your firewall try disabling it and re-connect
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
-
Jun 4th, 2010, 07:39 PM
#3
Re: SQL Connection Error
You query?
Maybe you pass something that does not compile.
a wrong date format p.e.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jun 4th, 2010, 10:09 PM
#4
Thread Starter
New Member
Re: SQL Connection Error
Here is the code: (I took my credentials)
Dim cn As New SqlClient.SqlConnection
Dim bd As New BindingSource
cn.ConnectionString = "Data Source=SERVER,3306;Initial Catalog=_test;User ID=***;Password=***"
cn.Open()
Dim co As New SqlClient.SqlCommand("Select * from users", cn)
bd.DataSource = co.ExecuteReader
datagridview1.datasource = bd
cn.Close()
-
Jun 4th, 2010, 10:15 PM
#5
Re: SQL Connection Error
Can you show us the exception's stack trace? From what you've said, it sounds like that error is occurring fairly deep. It's not something you'd expect from an invalid value in a connection string.
-
Jun 4th, 2010, 10:28 PM
#6
Re: SQL Connection Error
pretty ugly connection string though..
if that was pasted directly from your code, try:
"Data Source=SERVER;Initial Catalog=_test;User ID=***;Password=***;"
also, I don't see where you're calling co.ExecuteNonQuery()
Try adding it after this line: Dim co As New SqlClient.SqlCommand("Select * from users", cn)
-
Jun 4th, 2010, 10:47 PM
#7
Thread Starter
New Member
Re: SQL Connection Error
Thanks for the replies
I need to specify the port in the connection string or it doesn't connect.
-
Jun 4th, 2010, 10:52 PM
#8
Re: SQL Connection Error
is this MySql, SQL 2005, SQL 2008?
I've only the seen ports be used in a connection string if you specify an IP Address of the server. If it's SQL, the port shouldn't need to be changed unless you specifically run your SQL on a different-than-default port.
-
Jun 4th, 2010, 10:57 PM
#9
Re: SQL Connection Error
I'm not a SQL Server expert so I may be off base here, but I've only ever seen the port number used along with an IP address rather than with a server name. What happens if you change the server name to an IP address?
EDIT: Apparanetly I'm a bit slow. To elaborate and add value to my otherwise redundant post, I believe that the connection is made using named pipes when specifying a server/instance name, while it's made using TCP/IP if an IP address is used. As port numbers are a TCP/IP thing, the port number is only relevant to a connection made over TCP/IP.
-
Jun 4th, 2010, 11:02 PM
#10
Thread Starter
New Member
Re: SQL Connection Error
Tried changing it to numbers, same error. If I take the port out, I get:
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I'm almost positive it allows remote connections too.
EDIT: It's mysql
-
Jun 4th, 2010, 11:08 PM
#11
Re: SQL Connection Error
OK, this:and this:are NOT the same thing. When most people say just "SQL" they are usually being lazy and they mean SQL Server (which annoys me). In your case, you're also using SqlClient, which added weight to that implication. SqlClient is ONLY for SQL Server. If you're database is MySQL (note the proper name "MySQL", not "my SQL") then you need an ADO.NET provider that supports MySQL. You can download such a provider, i.e. Connector/Net, from the MySQL web site. Download it, install it, reference it and then change all your code to use it. The conversion is simple because all the types correspond 1:1, e.g. use a MySqlConnection instead of a SqlConnection.
-
Jun 4th, 2010, 11:21 PM
#12
Thread Starter
New Member
Re: SQL Connection Error
ok, ill take a look. Thanks for your help
-
Jun 4th, 2010, 11:50 PM
#13
Thread Starter
New Member
Re: SQL Connection Error
jmcilhinney, where do I send the check.
Thanks for your help, everything is working perfect.
-
Jun 5th, 2010, 12:06 AM
#14
Re: SQL Connection Error
Originally Posted by Snik
jmcilhinney, where do I send the check.
Thanks for your help, everything is working perfect.
To my favourite charity at jmcilhinneyneedschocolate.com
-
Jun 5th, 2010, 04:39 AM
#15
Re: SQL Connection Error
Ok, from now on if i see "try to connect to my SQL" i will always ask if it's SQL db or Mysql so we don't have the same thing like in this thread.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jun 5th, 2010, 04:59 AM
#16
Re: SQL Connection Error
Originally Posted by sapator
Ok, from now on if i see "try to connect to my SQL" i will always ask if it's SQL db or Mysql so we don't have the same thing like in this thread.
You mean if it's SQL Server or MySQL, right? The fact that people say just "SQL" instead of "SQL Server" is part of the problem. SQL is a query language, not a database.
-
Jun 5th, 2010, 05:17 AM
#17
Re: SQL Connection Error
Originally Posted by jmcilhinney
SQL is a query language, not a database.
I know that, but the thing I wonder about is that in MySql and MSSQL some of the the query syntax is different, for example:
MSSQL
Code:
SELECT TOP 1 * FROM MyTable
MySql
Code:
SELECT * FROM MyTable LIMIT 1
so if SQL is the same language in both mysql and mssql how did they changed the syntax ? or they both wrote almost the same language from scratch following the SQL rules?
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
-
Jun 5th, 2010, 05:56 AM
#18
Re: SQL Connection Error
There are SQL standards for many things (such as the ORDER BY clause, the CREATE TABLE statement, etc), but not everything - so the extra things generally have different syntax for each database system (like LIMIT/TOP/etc), and are not necessarily supported by all database systems.
-
Jun 5th, 2010, 06:16 AM
#19
Re: SQL Connection Error
so the SQL language can be derived from and expend it ?
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
-
Jun 5th, 2010, 06:33 AM
#20
Re: SQL Connection Error
Originally Posted by motil
so the SQL language can be derived from and expend it ?
Each database vendor can do whatever they want. It's their database. They don't have to support SQL at all if they don't want to. It makes sense for them to though, because it saves them having to invent there own query language, plus it makes their database accessible to the huge number of people with existing SQL knowledge. It's then up to the vendor to decide what parts of the SQL standard they will support, what parts they won't support and what things they will add to distinguish their product and make it more useful and attractive to users. It's exactly the same situation as with browsers and how they support HTML, JavaScript, CSS, etc. Each of those languages has a written standard but it's up to each browser vendor to decide how close to the spec their support will run and if and how they will extend that standard.
-
Jun 5th, 2010, 06:40 AM
#21
Re: SQL Connection Error
thanks for the answer but this is exactly what i'm trying to ask,
if I theoretically decide to develop my own database server such as sql or mysql, will i have to write the whole SQL language by myself and follow the SQL standard (if i choose to) or there is 3rd side party which i can use that provide me all the SQL basic and i choose if to expend it or not?
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
-
Jun 5th, 2010, 07:43 AM
#22
Re: SQL Connection Error
Originally Posted by motil
thanks for the answer but this is exactly what i'm trying to ask,
if I theoretically decide to develop my own database server such as sql or mysql, will i have to write the whole SQL language by myself and follow the SQL standard (if i choose to) or there is 3rd side party which i can use that provide me all the SQL basic and i choose if to expend it or not?
You don't have to write any of the SQL lanaguage. The SQL language is already written. It's up to you implement, in code, the functionality associated with the SQL language. The SQL standard says that a user can execute the query "SELECT * FROM MyTbale" to get every column of every row in MyTable. It says nothing whatsoever about HOW that is achieved. As the database vendor, that's your job: to provide the implementation. It's also completely up to you to decide what you're going to support. There is no rule that says that supporting X means that you have to support Y and you can't support Z. As the database vendor, that is totally at your discretion. It comes down to common sense: there's no point straying from the SQL standard unless it serves a purpose. If you don't provide support for something that your average SQL user expects to be able to use then your average SQL user will probably not use your database. If you have an idea to make your database better by adding something that is not part of the SQL standard then it's completely up to you whether you do that. There are no SQL police to tell you that you can't.
-
Jun 5th, 2010, 08:12 AM
#23
Re: SQL Connection Error
Ok thanks for the answers!
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|