How To Open A Socket Connection Based On An Insert TRIGGER?

Mar 19, 2007

Hello,

Would it be possible to open a socket connection and send few data based on an insert TRIGGER?
My client would basically like to send the ID of  a product via socket connection when a new product is inserted into the SQL database.


Thanks for your help
Arnold

View 13 Replies


ADVERTISEMENT

How To Create A Socket/IP Connection Using SQL?

Jun 30, 2007

I just want to know how to create a socket/IP connection using SQL prodecure or function

please help..

thanx

View 3 Replies View Related

Insert / Update Trigger Based On A Column's Value

Jun 7, 2006

I am new to triggers and surely could use some help.

I can create a trigger to insert related records based on the main tables ID and insert that value into other related tables fine... but...

How do I create a trigger that can insert a record into one table for a columns given value and then insert a record into another table for another given value?

For instance:
New row...

Table1, Column1 (PK) has a value of 101
Table1, Column2 has a value of 'Blue'.

// When a new row is created in Table1 and Column2 has a value of 'Blue'...
I want to insert a new row into Table2 - with Table1 Column1's value.

// Now if Table1, Column2 has a value of 'Red' when the new row was created...
I want to insert a new row into Table3 - with Table1 Column1's value. Not Table2

This has to be inserted into one or the other tables based on column2's value, not both.
Then I want to populate the other related tables (Table4, Table5) with the regular insert statements based on Table1 Column1's value.

This (the conditional part above) has to work with an update to Table1 also.
So if someone came back to that record and changed Column2's value from 'Blue' to 'Red', it would have to delete the appropriate record in Table2 and then insert the new row into Table3 and visa-versa.

Can I do this with one trigger?

Thanks

View 8 Replies View Related

SQL 2012 :: Trigger After UPDATE INSERT Based On Column Value

Jul 18, 2014

I would like to change a value after the table updates inserts a new row based on the value of that column

Table Name is: MPanel
Col Names: RID, FPID.

I want to:

If column RID='16'
Then UPDATE FPID='1'

How can I trigger that update? Would this work:???

CREATE TRIGGER dbo.MyTrigLI
ON dbo.MPanel
FOR INSERT, UPDATE
AS
BEGIN
UPDATE [MPanel]
SET
FPID='1'
WHERE (UPDATE(RID='16')
END

View 9 Replies View Related

Leave The Connection Open Or Always Open And Close Immediately?

Jun 7, 2006

Hi there,
 
I got an approach like that:
1) Read something from DB - check the value, if true stop if false go on2) Read the second Value (another SQL Statement) - check the value etc.
Now I could open the connection at 1) and if I have to go to 2) I leave the connection open and use the same connection at 2). Is it ok to do that?
The other scenario would be opening a connection at 1), immediately close it after I read the value and open a new connection at 2).
Thanks for the input!

View 4 Replies View Related

CLR-Based Trigger? Recursive Trigger? Common Table Expression?

Nov 14, 2006

Hey,

I'm new to this whole SQL Server 2005 thing as well as database design and I've read up on various ways I can integrate business constraints into my database. I'm not sure which way applies to me, but I could use a helping hand in the right direction.

A quick explanation of the various tables I'm dealing with:
WBS - the Work Breakdown Structure, for example: A - Widget 1, AA - Widget 1 Subsystem 1, and etc.
Impacts - the Risk or Opportunity impacts for the weights of a part/assembly. (See Assemblies have Impacts below)
Allocations - the review of the product in question, say Widget 1, in terms of various weight totals, including all parts. Example - September allocation, Initial Demo allocation, etc. Mostly used for weight history and trending
Parts - There are hundreds of Parts which will eventually lead to thousands. Each part has a WBS element. [Seems redundant, but parts are managed in-house, and WBS elements are cross-company and issued by the Government]
Parts have Allocations - For weight history and trending (see Allocations). Example, Nut 17 can have a September 1st allocation, a September 5th allocation, etc.
Assemblies - Parts are assemblies by themselves and can belong to multiple assemblies. Now, there can be multiple parts on a product, say, an unmanned ground vehicle (UGV), and so those parts can belong to a higher "assembly" [For example, there can be 3 Nut 17's (lower assembly) on Widget 1 Subsystem 2 (higher assembly) and 4 more on Widget 1 Subsystem 5, etc.]. What I'm concerned about is ensuring that the weight roll-ups are accurate for all of the assemblies.
Assemblies have Impacts - There is a risk and opportunity impact setup modeled into this design to allow for a risk or opportunity to be marked on a per-assembly level. That's all this table represents.

A part is allocated a weight and then assigned to an assembly. The Assemblies table holds this hierarchical information - the lower assembly and the higher one, both of which are Parts entries in the [Parts have Allocations] table.

Therefore, to ensure proper weight roll ups in the [Parts have Allocations] table on a per part-basis, I would like to check for any inserts, updates, deletes on both the [Parts have Allocations] table as well as the [Assemblies] table and then re-calculate the weight roll up for every assembly. Now, I'm not sure if this is a huge performance hog, but I do need to keep all the information as up-to-date and as accurate as possible. As such, I'm not sure which method is even correct, although it seems an AFTER DML trigger is in order (from what I've gathered thus far). Keep in mind, this trigger needs to go through and check every WBS or Part and then go through and check all of it's associated assemblies and then ensure the weights are correct by re-summing the weights listed.

If you need the design or create script (table layout), please let me know.

Thanks.

View 4 Replies View Related

ExecuteReader Requires An Open And Available Connection. The Connection's Current State Is Closed.

Apr 26, 2007

I am accessing SQL2005 with C# code using OleDbConnection.



A try and catch block catches the following error once a while between the Open() and Close() of the connection:

ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.



I do not even have any idea where to start to debug this. The ExecuteNonQuery() runs a delete SQL query. It works 99.9% of the time. I do not see anything wrong when this error happens.



Any hint would be greatly appreciated.



View 9 Replies View Related

Open An ODBC Connection To A DB And Must Use A Connection That Looks Like This: DSN=myDSNname.

Dec 11, 2006

In my ssis package,

I have a DSN connection like this: "DSN=myDSNname". Which decide from i have to pull the data.

By using OLE DB Source Editor, I want to assign that ODBC Connection to it.

By data source Reader i can achive this but where i have to pass the hard-code SQL Query that i don't want.

i'm using the variable for dynamic SQL command.

Thanks.

Manoj

View 5 Replies View Related

Trigger - Require Help For Updating A Trigger Following An INSERT On Another Table

Oct 30, 2007

Table 1





First_Name

Middle_Name

Surname


John

Ian

Lennon


Mike

Buffalo

Tyson


Tom

Finney

Jones

Table 2




ID

F

M

S

DOB


1

Athony

Harold

Wilson

24/4/67


2

Margaret

Betty

Thathcer

1/1/1808


3

John

Ian

Lennon

2/2/1979


4

Mike

Buffalo

Tyson

3/4/04


5

Tom

Finney

Jones

1/1/2000


I want to be able to create a trigger that updates table 2 when a row is inserted into table 1. However I€™m not sure how to increment the ID in table 2 or to update only the row that has been inserted.

View 17 Replies View Related

Trigger - Require Help For Updating A Trigger Following An INSERT On Another Table

Feb 5, 2008

A





ID

Name


1

Joe


2

Fred


3

Ian


4

Bill


B





ID


1


4

I want to be able to create a trigger so that when a row is inserted into table A by a specific user then the ID will appear in table B. Is it possible to find out the login id of the user inserting a row?

I believe the trigger should look something like this:

create trigger test_trigger
on a
for insert
as
insert into b(ID)

select i.id
from inserted i
where
--specific USER

View 9 Replies View Related

Interaction Between Instead Of Insert Trigger And Output Clause Of Insert Statement

Jan 14, 2008


This problem is being seen on SQL 2005 SP2 + cumulative update 4

I am currently successfully using the output clause of an insert statement to return the identity values for inserted rows into a table variable

I now need to add an "instead of insert" trigger to the table that is the subject of the insert.

As soon as I add the "instead of insert" trigger, the output clause on the insert statement does not return any data - although the insert completes successfully. As a result I am not able to obtain the identities of the inserted rows

Note that @@identity would return the correct value in the test repro below - but this is not a viable option as the table in question will be merge replicated and @@identity will return the identity value of a replication metadata table rather than the identity of the row inserted into my_table

Note also that in the test repro, the "instead of insert" trigger actually does nothing apart from the default insert, but the real world trigger has additional code.

To run the repro below - select each of the sections below in turn and execute them
1) Create the table
2) Create the trigger
3) Do the insert - note that table variable contains a row with column value zero - it should contain the @@identity value
4) Drop the trigger
5) Re-run the insert from 3) - note that table variable is now correctly populated with the @@identity value in the row

I need the behaviour to be correct when the trigger is present

Any thoughts would be much appreciated

aero1


/************************************************
1) - Create the table
************************************************/
CREATE TABLE [dbo].[my_table](
[my_table_id] [bigint] IDENTITY(1,1) NOT NULL,
[forename] [varchar](100) NULL,
[surname] [varchar](50) NULL,
CONSTRAINT [pk_my_table] PRIMARY KEY NONCLUSTERED
(
[my_table_id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 70) ON [PRIMARY]
)

GO
/************************************************
2) - Create the trigger
************************************************/
CREATE TRIGGER [dbo].[trig_my_table__instead_insert] ON [dbo].[my_table]
INSTEAD OF INSERT
AS
BEGIN

INSERT INTO my_table
(
forename,
surname)
SELECT
forename,
surname
FROM inserted

END

/************************************************
3) - Do the insert
************************************************/

DECLARE @my_insert TABLE( my_table_id bigint )

declare @forename VARCHAR(100)
declare @surname VARCHAR(50)

set @forename = N'john'
set @surname = N'smith'

INSERT INTO my_table (
forename
, surname
)
OUTPUT inserted.my_table_id INTO @my_insert
VALUES( @forename
, @surname
)

select @@identity -- expect this value in @my_insert table
select * from @my_insert -- OK value without trigger - zero with trigger

/************************************************
4) - Drop the trigger
************************************************/

drop trigger [dbo].[trig_my_table__instead_insert]
go

/************************************************
5) - Re-run insert from 3)
************************************************/
-- @my_insert now contains row expected with identity of inserted row
-- i.e. OK

View 5 Replies View Related

Need A Trigger Based On A Row

Feb 18, 2005

Hello, everyone

I need to create a trigger to update a FLAG column by row modification. The table likes,

Col1FLAG
a0
b0
c0
d0
e0

If "a" in Col1 is changed, the "0" in same row (First row) should be changed to '1'. Other FLAG values should not be changed. The same rule for other row.

Anyhelp will be approciated.

Thanks a lot

ZYT

View 4 Replies View Related

Multiple Insert Call For A Table Having Insert Trigger

Mar 1, 2004

Hi

I am trying to use multiple insert for a table T1 to add multiple rows.

Ti has trigger for insert to add or update multiple rows in Table T2.

When I provide multiple insert SQL then only first insert works while rest insert statements does not work

Anybody have any idea about why only one insert works for T1

Thanks

View 10 Replies View Related

Time Based Trigger

Feb 16, 2005

can i make a trigger to fire based on given date and time?

View 2 Replies View Related

Error While Establishing A Connection To The SQL Server 2005 - Could Not Open A Connection To SQL Server

Apr 12, 2007

Hi, I had an old web application created during asp.net 1.1 and it have a connection problem with the sql server 2005 when it is mirgrated to a new webserver with dotnet framework 2.0 platform. I have enabled the remote access(TCP/IP and named pipes) in sql server 2005, did all the neccessary things, check whether the TCP/IP is enabled, named pipe is enabled...  I created another web application using VS 2005. The database connection works perfectly well.This are the connectionString from the old web application.<appSettings>    <add key="ConnectionString" value="Server=127.0.0.1;Database=somedb;User id=user; Password=somepassword; Trusted_Connection=False; POOLING=FALSE"/></appSettings>  Thankyou in advance! 

View 4 Replies View Related

Open Connection

Nov 1, 2007

Hello everybody I would like to know more about the number of possible connection to a sql server is it by pool ? or there is max for all the database ? all the server ? how I can get the number of connection open ? Thx in advance 

View 2 Replies View Related

Could Not Open Sql Connection

Sep 22, 2007



Hi,
I hope this is right place to ask for help.If it is not, Please show me where and if it is please Help me
I using Window Vista bussiness, Microsoft visual 2005 professional edition, Microsoft SQL server express edtion
I have created table on Database.
My sql server name is KYAW-HQ
**but in the bar it shown like as KYAW-HQSQLEXPRESS
My data base name is kyaw
I have already Enabled Name Pipes and TCP/IP setting in sql studio management tool express
I using window authentication to log in to sql server management studio express.

My coding for c# is as follow:


private void button4_Click(object sender, EventArgs e)

{

//connect sql connection

SqlConnection con = new SqlConnection("Server=KYAW-HQ;Database=kyaw;UID=;PWD=;");

//open sql conection

con.Open();

SqlDataAdapter ad = new SqlDataAdapter("Select * From kyaw", con);

DataSet ds = new DataSet();

ad.Fill(ds, "kyaw");

dataGridView1.DataSource = ds.Tables[0].DefaultView;

con.Close();





}



After I click the button the error has shown like below

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server).

Please tell me what i have to do.
If someone read me, please tell me and advice me how to fix above problem.
Thanks

View 9 Replies View Related

Cannot Open SQL Connection

Jan 22, 2008

Hello!

This code sample stops when I try to open a connection (see below). Ther error message reads "pipe provider , error 40". The help suggests that the credentials are wrong. I don´t think so, could there be another problem? Tough question but, I would appreciate any help.


System.Data.SqlClient.SqlConnection sqlConnection1 =

new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["SwimAdminConnectionString"].ConnectionString);



System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();

cmd.CommandType = System.Data.CommandType.Text;

string sql1 = Session["txtFirstName"].ToString();

string sql2 = Session["txtLastName"].ToString();

cmd.CommandText = "INSERT dbo.Member (mbrFirstName, mbrLastName) VALUES (sql1, sql2)";

cmd.Connection = sqlConnection1;

sqlConnection1.Open(); //EXCEPTION HERE!!!

cmd.ExecuteNonQuery();

sqlConnection1.Close();

View 26 Replies View Related

How To Write Trigger Based On Certain Condition

Nov 8, 2005

One of my table called as 'customertable' contains following fields

customername, emailid, subscriptionendperiod

Example records are:

david, david@john.com, 12/20/2005(mm/dd/yyyy format).

My question is that: Just one month before subscriptionendperiod that is on 11/20/2005(mm/dd/yyyy) an automatic email should go to david@john.com with the message 'Your subscription period ends on 12/20/2005'

How to write trigger for this.

Please Note : No ASP code is invloved in this.
Only MSSQL coding to be done.


Regards

View 3 Replies View Related

Trigger Based On Specific Field??

Jan 11, 2008

Do triggers work on the field level or only for full table updates, etc...?

I want to have a trigger that will change a field on another table based on the update of a specific field on a table.

Could anyone provide a sample please, if this is possible?

Thank you!

View 3 Replies View Related

Could Not Open A Connection To SQL Server

Nov 25, 2007

Hi, Has somebody had a problem like this before? Exception Details: System.Data.SqlClient.SqlException:
An error has occurred while establishing a connection to the server.
 When connecting to SQL Server 2005, this failure may be caused by the
fact that under the default settings SQL Server does not allow remote
connections. (provider: Named Pipes Provider, error: 40 - Could not
open a connection to SQL Server) That's part of the code:        SqlConnection con;        string sql;        SqlCommand cmd;               con=new SqlConnection("Data Source=elf/SQLEXPRESS;Initial Catalog=logos;Integrated Security=SSPI;");        sql="SELECT max(id_kandydat) from Kandydat";        con.Open();         cmd=new SqlCommand(sql,con);        int id = Convert.ToInt32(cmd.ExecuteScalar());        con.Close();         SqlDataSource7.InsertCommand="INSERT INTO Kandydat_na_Kierunek(id_kandydat, id_kierunku, id_stan) VALUES ("+"'"+id+"'"+","+"'"+DropDownList1.SelectedValue+"'"+","+'1'+");";  I don't really get it. I'm nearly 100% sure that before some changes in my project this had worked perfectly. Does anybody have any idea how to make it work again? I would be very grateful for any help. And, yesy, I know it is quite common error, but proposed solution found didn't help.Regards,N.  

View 5 Replies View Related

Leave DB Connection Open

Mar 20, 2008

Hello, I have always closed my db connections asap after opening them and have always thought this was the best practice.  But now I am wondering if I can just leave the connection open.
I created a windows service which runs on a timer and executes every 5 seconds.  The problem is that the code takes longer than that to process and the code may be executing three times at once. Im worried that since I use the same connection each time the code executes that a connection opened by the first run through may be closed or reopened by the second or third running of the code resulting in an error.  The connection is opened and closed about 10 times each time the timer event fires.  Should I open the connection once and leave it open when the service is started and close it when it is stopped or on any error?
 
Thanks

View 2 Replies View Related

Could Not Open A Connection To SQL Server

Jun 3, 2008

i m getting this exception
"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
i want to know that this exception is from my end or on Server End. because 5 to 6 month my application works fine but in these days i m getting this exception 5 to 20 times a day
your help will really appricate...
 

View 5 Replies View Related

How Trace That Where The Connection Is Open

Jun 14, 2006

hi to all,
I create a web application in asp.net with sql server 2000, I use always close connection in .net code as my consern but when run my application then visit page to page give a error "General network error " message . then i check lots of connection is sleeping state in process info in sql manegment(current activity) Now i open the particular processId in Process info show open connection with any storeprocedure name and show .net sqlclient data provoider referance as open connection which is fetch the data from sql then i check in code find really the connection which is got data by that store procedure is not close properly and i close it. This is ok but one problem is that some procesId show  blank info with .net sql client data provoider. so how can i find where these conneciton is open in my applicaton because this processId doesn't give any clue for it , it show nothing only blank but status is sleeping. If any help have this context then quick feedback.
Thanks

View 2 Replies View Related

Could Not Open A Connection To SQL Server

Feb 20, 2006

Hi,

One issue has got me stuck while getting to build an application(ASP.NET/SQLSERVER). Whenever I try to connect to SQL Server 2005 (installed on local host) using Visual Web Developer 2005 Databse Explorer, I get the following error message:

"An error has occured while establishing a connection to the server.
when connection to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - could not open a connection to SQL Server)"


NB:
- on SQL Servers' Surface Area Configuration, Remote connections are set to "Local and Remote connnections" and "Using both TCP/IP and named pipes".

ANyone with a solution? pse help

View 3 Replies View Related

Error: 40 - Could Not Open A Connection

May 8, 2007

I am developing a web service that uses a sql data connection.



The sql database is on a server, and the development version of my web service is on my pc.



I can connect/access the data accross my network when I run the service on my PC, but as soon as I put the web service onto the server(with the sql) it displays, the service wont function - error: 40 - could not open a connection....



I presume that sql is configured correctly as I am recieving data back when I request it accross the network. I dont understand why it wont work when I have the service on the server with the sql?



Any help will be appreciated.



View 4 Replies View Related

Could Not Open A Connection To SQL Server

Jan 25, 2008

tried to install SQL Server 2005 in a fresh installed Windows 2003 SP2. And this server is a workgroup member, not a member of a domain.

The services (Database service, integration service, reporting services and so on) work fines, but I could not connect to server

I checked the log, I found the following error,error :40-Could not connect to SQL Server(Microsoft SQL Server,Error-1231).


I never had this problem and this time, I really got the trouble and do not have solution.

Who have ever encounter this problem? Or someone can help me?

Thanks.

View 1 Replies View Related

Open A DSN Connection In TSQL

Sep 21, 2006

I'm trying to update an SQL DB from data in Quickbooks. I am trying to find if I can open a dsn connection in a stored procedure, called from an ASP page, to the quickbooks db using odbc. The driver I have for odbc does not allow for linked servers. I'm very new to stored procedures and such so please bear with me. Thxs.

View 3 Replies View Related

Connection.Open(); Problem

Apr 17, 2008

hello ,i write this code
string sql="SELECT * FROM Customers";
SqlConnection connection = CollectionManager.getHotelConnection();
SqlCommand command = new SqlCommand(sql,connection);
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
result = command.ExecuteScalar();
connection.Open();
...
and when the debug goes to
connection.Open ()
it throws me this

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

but i have all enabled ,browser running normally ,name pipes tcp ip enable all ,but it makes me this thsi all the time what mayb e huppens there?

View 4 Replies View Related

How To Open A Second Connection While In A Datareader

Dec 13, 2007



Hi,

I hope someone can help me with this.

I have created a data reader to loop thru a table and build an update statement.
Now I need to execute this statement in the datareader loop but the connection object is in use.

I tried creating another connection object but get an error:
"The context connection is already in use."

Is there a way to open another connection while the main context connection is open.
Just to make it clear, I do not want to read all the rows into memory first and then call update, it has to
happen for each iteration of the datareader.

Thanks.
--
With Regards
Shailen Sukul
Software Architect/Developer/Consultant
(BSc | Mcts (Biztalk (IP)) | Mcpd | Mcts (Web, Win, Dist Apps) | Mcsd.NET | Mcsd | Mcad)
Ashlen Consulting Services Pty Ltd
(http://www.ashlen.com.au)
MSN | Skype | GTalk Id: shailensukul
Ph: +61 0421 277 812
Fax: +61 3 9011 9732
Linked In: http://www.linkedin.com/in/shailensukul

View 7 Replies View Related

Open Connection In Sql Server

Feb 9, 2006

Try
Dim l_connString As String

l_connString = "Server=kangalert;database=Order;user id=sa;password=123;"
m_cn = New SqlConnection(l_connString)
m_cn.Open()

Catch ex As SqlException
Dim l_sqlerr As SqlError
For Each l_sqlerr In ex.Errors
MsgBox(l_sqlerr.Message)
Next
End Try



i got this in my mobile application, which try to open a connection directly to the sql server, but i got the following message

General Network error, check your network documentation.

View 7 Replies View Related

How To Access Another Server's Sql Through Socket/tcp Link

Feb 21, 2008

 hi, A and B are different asp.net projects. Each has its own sql database, and is linked to each other through socket/TCPListener.how can page B access the data in sql of A through this socket?thanks! 

View 2 Replies View Related

'socket' Visual Program Using Ms Sql Through Port 80

Aug 29, 2007

hi,

im an honours student from australia who is investigating the susceptability of medical application suites that use ms sql to sql injection.

this software is written in c/java (i think).

my supervisor advised me i could experiment socketing/porting the software through port 80 somehow so that i may communicate with the database.

can any one give me any info on software/techniques if there are any out there?

thanks in advance.

lee

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved