Error in Executing sqlcommand using smo.database.ExecuteNonQuery in vb6
-
sábado, 21 de abril de 2012 20:17
Hello,
I have created a COM Wrapper class in vb.net that includes smo objects .In that class I have included smo.database.ExecuteNonQuery method.
I included that dll in vb6 project.On Calling smo.database.ExecuteNonQuery from vb6 it is not executing the query.
Kindly suggest the solution.It will be a great help.All other functions are working fine.
Code snippet
VB.net Class Library(smolib)
Database Class(my own class)
added refrences
Microsoft.SqlServer.Management.Smo
Microsoft.SqlServer.Management.Common
Public Sub ExecuteNonQuery(Sqlcommand As String)
Microsoft.SqlServer.Management.Smo.Database.ExecuteNonQuery(Sqlcommand)
End Sub
VB6 Code
Dim database as new smolib.Database
database.ExecuteNonQuery "Alter table table_name drop constraint Drop Column Column_name"
This ExecuteNonQuery not working.
Please help.
Todas las respuestas
-
domingo, 22 de abril de 2012 16:00Moderador
Hello,
Please, could you tell us whether you are getting an error message ( if yes, could you provide the full error message ? )
I am not sure that SMO is working with non managed code ( i am not sure that VB6 is providing managed code ).
How are you providing the name of your database to your ExecuteNonQuery method ?
Please, could you provide the version ( 2000,2005,2008,2008 R2,2012 ) of your database ?
We are waiting for your feedback to try to help you more efficiently.
Have a nice day
PS : i would suggest to have a look at this link :
http://msdn.microsoft.com/en-us/library/ms205782(SQL.100).aspx
How your code is knowing the instance to connect and the database to modify ?
I have used VB6 since its release upto 2003 , but my remembrance is poor ( 10 years ago, it is far... even if i have a good memory)
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
-
lunes, 23 de abril de 2012 17:01
This thread appears to be a duplicate of the one you placed in the TSQL forum.
But:
Alter table table_name drop constraint Drop Column Column_name
is not a valid SQL statement
Chuck
-
lunes, 23 de abril de 2012 18:03Error am getting is "ExecuteNonQuery failed for database_name".
-
lunes, 23 de abril de 2012 18:04sql statement is 'Alter table table_name Drop Column Column_name"
-
lunes, 23 de abril de 2012 18:12
VB6 CODE
Dim database as smolib.Database
Dim server as new smolib.server
set database=server.Databases("HQAdmin")
database.ExecuteNonQuery "Alter table Item Drop Column Price"
My actual code
-
lunes, 23 de abril de 2012 18:21
Shouldn't this:
database.ExecuteNonQuery "Alter table Item Drop Column Price"
Be this:
database.ExecuteNonQuery ("Alter table Item Drop Column Price")
Chuck
- Editado Chuck Pedretti lunes, 23 de abril de 2012 18:25
-
lunes, 23 de abril de 2012 18:24And if you are going through all the trouble of using SMO, why are you not using the Table/ColumnCollection/Remove method?
Chuck
-
lunes, 23 de abril de 2012 18:34the problem is not only for this sql statement.there are several other sql statements which i need to execute like removing the constraints from the table.
-
lunes, 23 de abril de 2012 18:38
try prefixing the tablename with its schemaname
database.ExecuteNonQuery ("ALTER TABLE dbo.Item DROP COLUMN Price")
I assume your account actually has permissions to alter tables?
Also there should be more to that error message than just "ExecuteNonQuery failed for database" - where is the rest of the error - take a look at the inner exception
Chuck
- Editado Chuck Pedretti lunes, 23 de abril de 2012 18:40
-
miércoles, 16 de mayo de 2012 8:00
You can also ask your query on this forum, it may help you.
http://www.sqlservercentral.com/Forums/Topic594345-22-1.aspx
-
miércoles, 02 de enero de 2013 23:21Moderador
Any specific reason why you are using COM Wrapper class?. Also please take a look at VB6 support policy http://msdn.microsoft.com/en-us/vstudio/ms788708.aspx
Can you post sample project in this forum so that community members can review the code and help you out.
Thanks, Sethu Srinivasan [MSFT] SQL Server http://blogs.msdn.com/sqlagent -------------------------------------------------------------------------------- This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

