| | |
C# failing to drop stored procedure from SQL Server using SMO
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
![]() |
•
•
Join Date: Apr 2006
Posts: 88
Reputation:
Solved Threads: 2
Hi all,
I have been trying to drop a stored proc for sometime using SMO. I can create with ease but can't seem to drop. Any ideas? I thought it might be permission but for testing used SA account. No luck...
I keep geting a error of "You cannot execute this operation since the object has not been created". It is created, I can execute it, I can modify it, heck I can even delete it in SQL Management Studio with no problems.
???
I have been trying to drop a stored proc for sometime using SMO. I can create with ease but can't seem to drop. Any ideas? I thought it might be permission but for testing used SA account. No luck...
C# Syntax (Toggle Plain Text)
private void btnCreate_Click_1(object sender, EventArgs e) { SqlConnection sqlConn = new SqlConnection("Connection String HERE"); Microsoft.SqlServer.Management.Common.ServerConnection serverConn = new Microsoft.SqlServer.Management.Common.ServerConnection(sqlConn); Server svrSql = new Server(serverConn); Database db = svrSql.Databases["DBTest"]; StoredProcedure spNew = new StoredProcedure(db, "StoredProc"); spNew.TextMode = false; spNew.AnsiNullsStatus = false; spNew.QuotedIdentifierStatus = false; spNew.TextBody = "Select * from TestTable"; spNew.Create(); svrSql = null; } private void btnDestroy_Click(object sender, EventArgs e) { SqlConnection sqlConn = new SqlConnection("Connection String HERE"); Microsoft.SqlServer.Management.Common.ServerConnection serverConn = new Microsoft.SqlServer.Management.Common.ServerConnection(sqlConn); Server svrSql = new Server(serverConn); Database db = svrSql.Databases["DBTest"]; StoredProcedure spNew = new StoredProcedure(db, "StoredProc"); spNew.Drop(); svrSql = null; }
I keep geting a error of "You cannot execute this operation since the object has not been created". It is created, I can execute it, I can modify it, heck I can even delete it in SQL Management Studio with no problems.
???
•
•
Join Date: Apr 2006
Posts: 88
Reputation:
Solved Threads: 2
Man this sucks. It's always after I post a question I then answer it. You have to use the spNew.Refresh(). It believe it asks the SQL Server the current status of the stored proc. Then you are allowed to delete it with ease. 

C# Syntax (Toggle Plain Text)
private void btnDestroy_Click(object sender, EventArgs e) { SqlConnection sqlConn = new SqlConnection("Connection String HERE"); Microsoft.SqlServer.Management.Common.ServerConnection serverConn = new Microsoft.SqlServer.Management.Common.ServerConnection(sqlConn); Server svrSql = new Server(serverConn); Database db = svrSql.Databases["DBTest"]; StoredProcedure spNew = new StoredProcedure(db, "StoredProc"); //HERE IS THE KEY! spNew.Refresh(); spNew.Drop(); svrSql = null; }
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- filling combobox with data stored in a table in sql server (VB.NET)
- How to connect a SQL stored procedure to a windows application? (VB.NET)
- Must declare the scalar variables in storedprocedure in sql 2005 (MS SQL)
- ASP.net/Stored Proc & Login Verification (ASP.NET)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
- Sql2k, How to set or unset IDENTITY Property of a column through code or stored (Legacy and Other Languages)
- Working with SQL's Text data type (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: Compiling Problems code snippets
- Next Thread: Anyone using dotnet 3.0
| Thread Tools | Search this Thread |
.net access algorithm alignment array bitmap box c# c#gridviewcolumn check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datetime decryption degrees draganddrop drawing encryption enum excel file focus form format forms function gdi+ grantorrevokepermissionthroughc#.net hospitalmanagementsystem image input install java label list localization mandelbrot marshalbyrefobject math messagebox mouseclick mysql netcfsvcutil.exe numeric operator path photoshop php picturebox pixelinversion platform plotting pointer polynomial post programming properties radians read regex remote remoting richtextbox server sleep socket sql statistics string stringformatting study sun table teamsuite text textbox thread time timer update usb usercontrol validation visualstudio webbrowser whileloop winforms wpf wpfc# xml





