|
You can use parameters, something like this:
cmd.CommandText = "INSERT INTO cdr_log (cdr_row) values (?p_cdr_raw)";
cmd.Parameters.Add("p_cdr_raw", MySqlDbType.VarChar);
...
cmd.Parameters["p_cdr_raw"].Value = cdr_raw;
cmd.ExecuteNonQuery();
|
|
|
|
|
jrahma wrote: so how can I avoid the error?
The tick is a special character. You are ignoring that possibility.
That is the cause of the error.
There can be other special characters as well.
As noted in the other reply you should use parameter replacement, which many database APIs (different types, different programming languages) provide.
If you absolutely cannot do that then you would need to either
1. Determine what special characters exist for your database and deal with them yourself.
2. Limit all input to a known safe set of characters and verify each input value FIRST before attempting to use it in SQL.
|
|
|
|
|
Hi,
I have one machine (PC-A) running XP Pro and SQL Server 2005, and another machine (PC-B) running XP Pro and Visual Studio 2005. Both are on my local network. They can see each other.
On PC-B, I tried to connect to PC-A SQL Server, but failed. PC-A SQL Server is allowing remote connections. Windows Authentication is used for connections. What else did I not set right? Thanks!
Best,
Jun
|
|
|
|
|
AFAIK you may have to add rules to your server's firewall, so it allows inbound traffic on TCP port 1433, and possibly also UDP port 1434.
If it still fails to connect, watch the error message closely; stuff it in the Google search box and/or show it here.
|
|
|
|
|
Thabks for reply.
After I added TCP port 1433 and UDP port 1434 to PC-A firewall exceptions and tested connection, I got the error "Login failed for user 'PC-A\Guest'". How can I set up Windows Authentication login properly?
In my case, it is not a domain environment. There is no common domain account, but individual accounts on each machine.
Best,
Jun
|
|
|
|
|
I don't know how to do that with Windows authentication; I did solve it once using SQL Authentication: just give your database and your app the same username and password, so tje DB can be accessed from everywhere by anyone running your app. May not be the safest way, but it works.
|
|
|
|
|
Thanks.
I added PC-A's "Guest" account to the SQL Server's "Security\Logins" group and mapped it to specific databases I want to connect. Here, I might have broken some security, but at least got it working for now.
Best,
Jun
|
|
|
|
|
Hi,
I have a sql server table with fields EmployeeID, Date, TimeIN, TimeOut, Remarks.
Now there is a unique constraint on both EmployeeID and Date such that only one record exists for a particular Employee on a particular date.
Now the main application can insert and update records. I need a trigger to track changes such that on insert or update, the values are copied onto a data_log table. Here is the problem, I need the trigger to check if the row exists in data_log for that EmployeeID and Date, then update, else insert. So there should be only one record of each employee per date in the data_log table as well. I just want the most current change and need to overwrite previous log entry.
thanks
|
|
|
|
|
Just a thought... why are you bothering if all you are doing is copying the values into another table? An audit or log table should contain complete history, I've always thought and no unique keys from the parent table - duplicates are fine - create a compound index or a surrogate key if you need one. Prepared to be called out on this - just seems a bit pointless.
In the meantime you could check with:
if exists(select top 1 1 from [table] where [key] = [parameter])
begin
end
else
begin
end
or similar: adjust to suit.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
I have to run extended operations on bulk records in the destination table.
I thought Delete if exists, then Insert would be a possible solution, but the trigger is working some times and failing other times, and when it does fail, it cancels out the transaction on the original table resulting in data loss.
|
|
|
|
|
I do not know which version of SQL server you have but if 2008 try MERGE in your trigger.
|
|
|
|
|
Hi,
I have two mysql tables with large amount of data.
Table_1 has fields PropID, FullStreetAddress, City, State, Zipcode, Remarks, Date which I want to pick. Table_2 has PropID,URL.
Now I want to pick top 60 rows from table_1 order by date desc. Each PropID has several URL records in Table_2. Out of those records, I need to pick only 4 for each PropID in table_1.
So in effect I would get a result set of 60 x 4 = 240 rows.
Selecting from table_1 and inner joining on PropID in table_2, I am getting a complete result set, but I need to limit that somehow to get 60 rows from table_1 and 4 rows for each of the 60 ids from table_2 in a single query.
thanks.
|
|
|
|
|
use
LIMIT 60 to get 60 rows from table_1
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
I know that part. But I need to create a View of some sort with 60 x 4 = 240 rows, I cant use Limit for both tables in a single query now, can i?
|
|
|
|
|
Only the first part of the solution: how to get the 60 rows from table_1:
SELECT table_1.PropID, FullStreetAddress, City, State, Zipcode, Remarks, Date, table_2.URL
FROM table_1 LEFT JOIN table_2 ON table_1.PropID=table_2.PropID
WHERE table_1.PropID IN
(SELECT PropID
FROM table_1
WHERE <your selection criteria>
LIMIT 60)
That's still with all releated rows from table_2.
|
|
|
|
|
ALTER PROCEDURE [dbo].[insert_task_details11]
@taskname varchar(150),
@completiondate varchar(30)
AS
BEGIN
DECLARE @DataID int
select DataID=MAX(taskid) from tblTaskAssign;
insert into tblJobs (taskid,taskname,completiondate) values (DataID,@taskname,@completiondate)
END
I want to insert maximum taskid into tblJobs.
It gives Error The name "DataID" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
and if I use @DataId instedat od DataID, null value goes in taskid in tblJobs.
How to solve this problem
thanks
|
|
|
|
|
Uma Shankar Patel wrote: select @DataID=MAX(taskid) from tblTaskAssign;
insert into tblJobs (taskid,taskname,completiondate) values (@DataID,@taskname,@completiondate)
Should work assuming that there are TaskID's in tblTaskAssign.
|
|
|
|
|
values are inserted but in TaskId column Null value inserted in tblJobs table.
i.e.
DataId is not inserted or not fetched properly from tblTaskAssign to be inserted into tblJobs
|
|
|
|
|
try this
DECLARE @DataID int
set @DataID = (select isnull(max(taskid),0) from tblTaskAssign)
insert into tblJobs (taskid,taskname,completiondate) values (@DataID ,@taskname,@completiondate)
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
|
hi friends
i created a database in sqlserver2008 throught management studio now i edited one of my table ie inserted a new column in it and want to save it. but it says that the changes cannot be saved so how to do it plz let me know.
K.Gayathri
|
|
|
|
|
What else does it say about it? Is it because you have the table open in another window?
|
|
|
|
|
|
Did you define the new column to not allow NULL ? If so, then you need to define a default value for that column.
|
|
|
|
|
Today I wanted a function (in SQL Server 2008) to return the lesser of two integers, but it didn't seem to exist, so I wrote one, then decided that it might be somewhat more useful sometime in the future if it wasn't coded for integers, so I changed it to use numeric instead:
CREATE FUNCTION dbo.LesserOf
(
@Op1 NUMERIC
,
@Op2 NUMERIC
)
RETURNS NUMERIC
AS
BEGIN
DECLARE @result NUMERIC
IF ( @Op1 < @Op2 )
SET @result = @Op1
ELSE
SET @result = @Op2
RETURN @result
END
Is there some odd limitation involved with numeric that I don't know about (I never use them)?
Is there a better way to implement this simple function (not a CASE)?
Is there a built-in LesserOf function?
|
|
|
|