Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi! I'm developing a queuing system using vb.net and I changed my database from ms access to sql server 2014, after I change the connection string and debugged my program an error box appeared that said "Keyword:"Provider" is not supported.". I don't know how and what I should do to make my program save data to my sql database. What is the correct code syntax for this program? Thanks!

What I have tried:

Imports System.Data.SqlClient



Dim sqlconn As New SqlConnection
       Dim sqlquery As New SqlCommand
       Dim connString As String
       Try
           connString = "Provider=SQLNCLI11;Data Source=MISKRISTIAN-PC\HMO_OPD;Integrated Security=SSPI;Initial Catalog=HMO_OPD_QUEUE"
           sqlconn.ConnectionString = connString
           sqlquery.Connection = sqlconn
           sqlconn.Open()
           sqlquery.CommandText = "INSERT INTO Query1([Number])VALUES(@Number)"
           sqlquery.Parameters.AddWithValue("@Number", NumApp.Text)
           sqlquery.ExecuteNonQuery()
           sqlconn.Close()
       Catch ex As Exception
           MessageBox.Show(ex.Message)
       End Try
Posted
Updated 24-Oct-17 9:04am

SQL does not support the "Provider" keyword - remove it up to and including the first semicolon and it should work.

But do yourself a favour and never hard-code connection strings. The number of place you have to change it when you release to production is ridiculous and generally means your code is not properly tested when you publish it. Use a configuration file, or see this: Instance Storage - A Simple Way to Share Configuration Data among Applications[^]
 
Share this answer
 
Comments
Maciej Los 24-Oct-17 15:08pm    
There's another "reverse of the medal" ;)
noob_noob 25-Oct-17 20:38pm    
Hi! is there any way I can convert my code to a compatible one for sql server?
OriginalGriff 26-Oct-17 2:27am    
And I quote: 'SQL does not support the "Provider" keyword - remove it up to and including the first semicolon and it should work.'
Why are you using SQL Server Native Client 11.0 OLE DB Provider? Note, that "OLE DB and ODBC does not support some of the new features in SQL Server 2005 and later. The managed .Net providers does. The SQL Native Client can be seen as a solution to have access to the new SQL Server features from native (non .Net) code. There are no other benefits from using it." See: When to use the SQL Native Client[^]

I'd strongly recommend to use .NET Framework Data Provider for SQL Server. See: SQL Server connection strings - ConnectionStrings.com[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900