Solved

Creating SQL Trigger via Code

Posted on 2004-09-14
5
217 Views
Last Modified: 2010-04-23
Does anyone know how to manage trigger via code, I'm more interested in being able to delete and create triggers from within my application (VB.Net).

VBSMerlin
0
Comment
Question by:VBSMerlin
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:RacinRan
ID: 12057206
If it's SQL Server ... send the database drop trigger and create trigger statements.

Racin


0
 
LVL 1

Author Comment

by:VBSMerlin
ID: 12057967
but how would i send that from code just as a regular sql command??? or is there something in the framework that can take care of that?

VBS
0
 
LVL 3

Expert Comment

by:RacinRan
ID: 12058016
Should be able to just send as a regular sql command.
0
 
LVL 1

Author Comment

by:VBSMerlin
ID: 12058076
RacinRan,  I will leave this open for about 2 hours to see if i get any other comment otherwise the points are yours

VBSMerlin
0
 
LVL 7

Accepted Solution

by:
natloz earned 250 total points
ID: 12058312
Here is a code snippet...

Dim cDB As clsDBConn = New clsDBConn 'Connection Class
        Dim strConn As String = cDB.getStrConn 'Get connection string for database
        Dim oConn As New SqlConnection 'SQL connection object
        Dim intReturnID As Integer 'Return ID from Stored Procedures
        Dim oComm As SqlCommand 'SQL Command object

        Try
            'Pass connection string to SqlConnection
            oConn.ConnectionString = strConn

            'SQL Database statements
            oComm = New SqlCommand
            oComm.CommandType = CommandType.Text
            oComm.CommandText = "drop trigger trg_test"
            oComm.Connection = oConn

            oConn.Open() 'Open connection
            oComm.ExecuteNonQuery() 'Execute SQL Statement to drop trigger
            oConn.Close() 'Close connection

        Catch ex As Exception
            MsgBox(ex.ToString)
            MsgBox("Error connecting to SQL Server")
        End Try

        'Return the ID added or ERROR Code
        Return intReturnID
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now