GarySB
asked on
Calling Stored Procedure from VB express 2008
I created a stored procedure that performs an update on a single field and now i want to call it from my vb application. Below is what I have tried with some variations.
EXEC (StoredProcedure7)
OR
Dim i As Int16
i = CompanySetupDataSetTableAd apters.Exe cuteSQL("S toredProce dure7")
Also, how do I rename a stored procedure?
EXEC (StoredProcedure7)
OR
Dim i As Int16
i = CompanySetupDataSetTableAd
Also, how do I rename a stored procedure?
To rename a stored procedure you can use in a function this
EXEC sp_rename 'oldname', 'newname'
EXEC sp_rename 'oldname', 'newname'
ASKER
Thank you for responding so quickly.
Can the above code you wrote be referenced using one of my existing data connections?
I'm already able to read and write to the tables with the below connections.
SetupDataSet, TableAdapterManager, TableAdapter or BindingSource
Thanks
Can the above code you wrote be referenced using one of my existing data connections?
I'm already able to read and write to the tables with the below connections.
SetupDataSet, TableAdapterManager, TableAdapter or BindingSource
Thanks
I believe that the TableAdapter can use a Stored Procedure as it's source. You just have to find and populate the SelectCommand I believe.
ASKER
Can you give me a sample of the syntax using my names please. I thought the GETDATA might be usefull, but does not appear to be for this.
ProjectDataTableAdapter, StoredProcedure7
ProjectDataTableAdapter, StoredProcedure7
ASKER
I'm trying to use your solution. How can I correct this error?. I'm trying both of these and I keep getting the same error:
Cannot open database "<C:\Documents and Settings\user\My Documents\CompanySetup.mdf >" requested by the login. The login failed. Login failed for user 'HP2\user'.
'HP2\user' is correct because it shows in the properties of the database.
The database does not have a password and the properties shows that the bottom one below is exactly the right path. I also tried the C: drive location. The database is on my local computer
Dim myConnectionString As String = _
"Data Source=.\SQLEXPRESS;Databa se=<C:\Doc uments and Settings\user\My Documents\CompanySetup.mdf >;Integrat ed Security=SSPI"
Dim myConnectionString As String = _
"Data Source=.\SQLEXPRESS;Databa se=<Compan ySetup.mdf >;Integrat ed Security=SSPI"
Cannot open database "<C:\Documents and Settings\user\My Documents\CompanySetup.mdf
'HP2\user' is correct because it shows in the properties of the database.
The database does not have a password and the properties shows that the bottom one below is exactly the right path. I also tried the C: drive location. The database is on my local computer
Dim myConnectionString As String = _
"Data Source=.\SQLEXPRESS;Databa
Dim myConnectionString As String = _
"Data Source=.\SQLEXPRESS;Databa
Try this connection string instead.
Server=.\SQLExpress;Attach DbFilename =C:\Docume nts and Settings\user\My Documents\CompanySetup.mdf ;Database= CompanySet up; Trusted_Connection=Yes;
Server=.\SQLExpress;Attach
ASKER
Hi dbaduck, I appreciate your help, but it is still not cooperating with the open statement. I placed the error msg below along with the exact code in my program.
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Dim myConnectionString As String = _
"Data Source=.Server=.\SQLExpres s;AttachDb Filename=C :\Document s and Settings\user\My Documents\CompanySetup.mdf ;Database= CompanySet up; Trusted_Connection=Yes;"
Using connection As New SqlClient.SqlConnection(my Connection String)
connection.Open() 'STOPS HERE
Using command As New SqlClient.SqlCommand("Stor edProcedur e7", connection)
command.CommandType = CommandType.StoredProcedur e
' If you want to pass some parameter
command.Parameters.Add("@C hangeFlag" , SqlDbType.Text).Value = "J"
command.ExecuteNonQuery()
End Using
End Using
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Dim myConnectionString As String = _
"Data Source=.Server=.\SQLExpres
Using connection As New SqlClient.SqlConnection(my
connection.Open() 'STOPS HERE
Using command As New SqlClient.SqlCommand("Stor
command.CommandType = CommandType.StoredProcedur
' If you want to pass some parameter
command.Parameters.Add("@C
command.ExecuteNonQuery()
End Using
End Using
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for working this out with me. Moving it to the local C: drive did the trick. I also wanted to show you the final connection string that worked.
"Data Source=.\SQLExpress;Attach DbFilename =C:\Compan ySetup.mdf ;Integrate d Security=True;User Instance=True;Trusted_Conn ection=Yes ;"
"Data Source=.\SQLExpress;Attach
Open in new window