|
Tim Carmichael wrote: Since I, personally, DETEST seeing SQL statements hard-coded in an application
That's where they belong, so you know they can't be easily changed. And it is to be hoped that any changes are properly tracked in your version control system with a proper paper trail and then tested.
Stored procedures are too fragile and should be avoided at all costs. I've even had stored procedures "disappear"... there one day, gone the next.
|
|
|
|
|
Hi All,
I am Stuck with xp_cmdshell to execute a Vb Script file?
Can Any one tell me about the folder permission i have to do on the folder when excuting through commandshell?
Thanks
|
|
|
|
|
Do not repost the same question. Just continue with your thread below.
|
|
|
|
|
Sorry Its Just by Mistake.
|
|
|
|
|
Hello All,
I am currently in the process of adapting an application that previously worked only with Microsoft Access to work with SQL server or Access. Previously, all database interaction was designed based upon using the XSD file to create queries (etc).
I wasn't sure how to handle the new situation with two types of database using the visual methods (e.g. did not want two separate datasets (etc) so I created a static class that contains a function as follows:
<br />
public static DataTable SelectRows(string connectionString, string queryString)<br />
The function will connect to either type of DB based on the connection string and will run the query held in queryString returning a table of the selected records.
I create a binding source and assign it to a table called masterTable as follows:
<br />
cards_photo_accesslevelBindingSource.DataSource = masterTable;<br />
I then have a DataGridView that points to the binding source as follows:
<br />
dgNavigatorTable.DataSource = cards_photo_accesslevelBindingSource;<br />
At various times in my code, I call the SelectRows method and store the returned table over the top of the masterTable as follows:
<br />
masterTable = MyQuery.SelectRows(MyConnectionStrings.getConnectionString(),<br />
"SELECT * FROM (Cards LEFT JOIN Photo ON Cards.Card = Photo.Id)LEFT JOIN AccLevel ON Cards.AccessLevel = AccLevel.AccessLevel WHERE Cards.FirstName LIKE '" + tbFirstName.Text + "%'");<br />
My first concern is that the binding source does not update in relation to the update of the table.
I have found that the only way to get the binding source and associated DataGridView to update after my masterTable has changed is to re-assign it as follows:
<br />
cards_photo_accesslevelBindingSource.DataSource = masterTable;<br />
Even using this naive technique, I also need at this point the PositionChanged event to fire on the binding source as it used to when I would call a Fill method on the datasource before I replaced this method with my SelectRows method.
I haven't done much C# for a while and previously have always used an XSD file for my database connection and queries and therefore I assume that I am using the binding source and DataTable in an illegal and naive way? I will keep searching the web for an answer and apologise in advance for my lack of understanding.
Regards,
Chris
|
|
|
|
|
Hi All,
I have a very strange problem with xp_cmdshell. Here is a Stored Procedure that is meant to execute a VB script file.When i run the VB Script independently it works fine.
But when i execute the stored procedure that is pointing to this VB script file it runs with No error But Doesnt do the work.
Stored Procedure
USE [Database]
GO
/****** Object: StoredProcedure [dbo].[sp_SendSMS] Script Date: 06/27/2010 10:14:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_SendSMS]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Numbers NVARCHAR(200)
DECLARE @Body NVARCHAR(160)
DECLARE @Command NVARCHAR(500)
-- Insert statements for procedure here
SET @Numbers = '00442345672'
SET @Body = CAST(GETDATE() AS NVARCHAR(20)) + ' Test Message'
-- TODO: Get Revenue Statistics and append them to @Command
SET @Command = 'd:\test\SendSMS.vbs /Numbers:' + @Numbers + ' /Body: "' + @Body + '"'
EXEC xp_cmdshell @Command
END
The VB script file is under test folder on D drive which has Read write permission set on the folder.
Set WshShell = WScript.CreateObject("WScript.Shell")
sNumbers= WScript.Arguments.Named.Item("numbers")
sBody= WScript.Arguments.Named.Item("body")
URL = "http://sampleweb.com/samplepage.aspx?IFVERSION=210000&MESSAGETYPE=10&OADC=00447956053317&MESSAGEID=3333&RECEIVETIME=20070320151916&BODY=This%20is%20my%204th%20message%20on%20the%20LIVE%20TV&MCLASS=2&HEADER=0048001&DESTADDRESS=1234&CONNECTION=MIG01l1&DCS=240&RETRYCOUNT=3&PID=0&AVSTATUS=1&GUID=9BBA5E93-390C-450C-94C3-1122E5D4858B"
WshShell.Run(URL)
Set WshShell = Nothing
When i run the VBS file Independently it works fine.However when running the stored procedure above which contains the file i dont see the file being excuted.
Could You please advice what is going Worng?
Thanks for your time.
modified on Sunday, June 27, 2010 6:43 AM
|
|
|
|
|
So let me get this straight; you're using a stored proc, to execute a VBS file which makes an http request to send an SMS? Multiple points of failure doesnt even begin to describe this monster.
Anyway, in answer to your question, its almost certainly a permissions problem. When you execute the VBS file directly, its running in the context of the currently logged in user. When you run it using xp_cmdshell its running in the context of whichever user SQL Server is running as.
|
|
|
|
|
Thanks for your reply.Its Much appreciated.I have already checked and changed the user who loggs in as An is An administartor.
Is there any thing i have to do to force the Login name to remain as the one who had access to that particualr folder.
Many thanks for your Info.
|
|
|
|
|
There are so many things wrong with that response.
It_tech wrote: I have already checked and changed the user who loggs in as An is An administartor
That is why you can run the VBS manually. your logged in user is an admin, and as an admin has rights to run the script. SQL Server runs as a service, it knows nothing about your logged in user, and has a completely different set of permissions.
It_tech wrote: Is there any thing i have to do to force the Login name to remain as the one who had access to that particualr folder.
This problem has exactly nothing to do with folder permissions. You can give a user permission to read a file from a folder, but they may still be denied things like "Execute processes".
If you have acccess to sys admins, ask them for help. If you dont then start reading up on the permission system in operation for the OS you're using. It varies quite substantially between older generation servers like Win2K and new generation servers like Win2K8.
Finally, nobody here will be able to help you on this problem, as none of us have access to your servers, and all servers are set up differently.
|
|
|
|
|
|
Thanks for the Reply.
I have checked the login on Sql Server 2008 using Services.msc and changed
the login to the login i use for windows.
Its is still the same.
Is there any advice you can suggest?
Thanks.
modified on Monday, June 28, 2010 9:34 AM
|
|
|
|
|
i have one table SAMPLENAME with 500 record
in which some record SampleName in Sample i want to find out those SampleName
How can i do this plz help
|
|
|
|
|
|
Dear All,
Please help me to JOIN 2 table from different server.
Thank you.
|
|
|
|
|
1. Some "more" (more than JOIN) information would help.
2. Read the guidelines at the top of this page.
3. Where is the question?
Greetings
Covean
|
|
|
|
|
So idea of what databases you're working with would help.
|
|
|
|
|
naunt wrote: Please help me to JOIN 2 table from different server.
Infrastructure/Environment fail.
Now, to answer your question; execute sp_addlinkedserver[^] to link the two servers, then using the server name to fully qualify a table, write a join in the normal way.
This post assumes MS SQL Server.
|
|
|
|
|
Thank you for your reply.
I am really really sorry for my uncomplete question.
I am using SQL server 2000.
@J4amieC, Thank you. Will try with "sp_addlinkedserver[^]".
|
|
|
|
|
I have a table in MS Access 2007 database I want to make a chart with, column chart (or whichever one is vertical). The table holds information on various species of insect I recorded over the year, so I could have multiple records for one species. Anyway what I have wanted to do, but haven't been able to figure out what is that:
I wanted to make a chart that had Jan, feb, march (all the way to december) on the X axis and up the Y axis I wanted a number (not sure of the number needed on it, up to 500 possibly) and what I wanted to do with the chart is show how many of a particular species I found each month of the year.
The fields I wanted to get the information with from the table are the scientific name, date, stage and quantity. The scientific name will be displayed as the title of the table and this is the species I want to find out about. The date is the date that month I recorded the species and the quantity is how many I recorded on that date. I have another field which is called "stage" and when you open the chart it will ask you two things, the scientific name and the stage as the stage (adult, larvae etc...) is quite inomrtant to what I want and I want the stage to be displayed on the chart.
Just say I wanted to know about Pieris Napi, I want to type this in when I open the chart, next type in Adult as the stage and I would get a chart showing Jan-December and the total I found each month in a column chart with its scientific name dispayed on title and stage (wether its an adult or pupae etc..)
Anyone know how would I do this? I think I would need to make a query from the table to get the information on the scientific name and stage, but not sure what else to do, any help would be appreciated.
In the end we're all just the same
|
|
|
|
|
I think you probably want to use a parametrized query with species as input.
I'm slightly confused about the stage - should the chart only show the selected stage or all stages?
If you go this route then the query should group by month and stage. That should easily be done in designer.
An alternative might be to use a PivotTable as the source for the chart.
My Access is pretty rusty but I think this is fairly straightforward. I'm not too good on charts - never really used them in Access.
Would it be better to give the user a list of species and allow them to select from the list. Saves all sorts of bother if the user gets the spelling wrong.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
Hi Dave,
First, for stage, prefer a drop down list to choose the stage and the results change accordingly, just show one type of stage, say a table showing the Pieris Napi at adult stage only.
What you suggested on having a drop down list to chose the scientific name would be far better, how would I do this so you can choose what you want proir to creating the table, would an input form work best for this, choose the scientific name and stage on a small form then press a button to take you to a chart on that species. I know how to create the form, but not how to get the information onto a chart
Havn't used much with charts or inputting data except on tables latley, so I am a bit rusty.
In the end we're all just the same
|
|
|
|
|
Hii..
I m in a great confusion. Can u help me?I want to calculate total work hours of a day using sql function.I m having three tables.
SG_Emp_Master,SG_Daily_Register,SG_Emp_Department.Employee ID,From date,ToDate are the parameters passed..Here is my code..But i could'nt get correct output.pls help me.
CREATE FUNCTION[dbo].[FN_TIME_ATTNDNC_REPORTS] ( @EMPID varchar(50)
,@FROMDATE datetime ,@TODATE datetime )RETURNS TABLE
AS RETURN(
SELECT DR_EmployeeID as EMPID,EM_FirstName+EM_MiddleName+EM_LastName as EMPNAME,ED_Department as DEPARTMENT,
SUBSTRING(CONVERT(VARCHAR,ES_TimeIn,9),14,15)+'-'+SUBSTRING(CONVERT(VARCHAR,ES_TimeOut,9),14,15)as SHIFTTIME,
CASE WHEN ((CONVERT(VARCHAR,DR_TimeIn,101)=CONVERT(VARCHAR,DR_TimeOut,101))AND(SUBSTRING(CONVERT(VARCHAR,DR_TimeIn,9),14,15)>'11:59:59:000PM'))
THEN
ISNULL(CONVERT(VARCHAR,DR_TimeIn,107)+' 12:01:00:000AM','Not checked')
ELSE
ISNULL(CONVERT(VARCHAR,DR_TimeIn,109),'Not checked')
END
AS TIMEIN,
CASE WHEN(CONVERT(VARCHAR,DR_TimeIn,101)!=CONVERT(VARCHAR, DR_TimeOut,101))
THEN
ISNULL(CONVERT(VARCHAR,DR_TimeIn,107)+' 11:59:59:000PM','Not checked')
WHEN (CONVERT(VARCHAR,DR_TimeIn,101)=CONVERT(VARCHAR,DR_TimeOut,101))
THEN
ISNULL(CONVERT(VARCHAR,DR_TimeOut,109),'Not checked')
END
AS TIMEOUT,
CASE WHEN(CONVERT(VARCHAR, DR_TimeIn,101)=CONVERT(VARCHAR, DR_TimeOut,101))
THEN
ISNULL(CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,DR_TimeOut)/3600)
+':'+
CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,DR_TimeOut )%3600/60)
+':'+
CONVERT(VARCHAR(5),(DATEDIFF(SS,DR_TimeIn,DR_TimeOut)%60)),'0 ')
WHEN(CONVERT(VARCHAR, DR_TimeIn,101)!=CONVERT(VARCHAR, DR_TimeOut,101))
THEN
ISNULL(CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,CAST(CONVERT(VARCHAR,DR_TimeIn,101)+' 11:59:59:000PM'AS DATETIME))/3600)
+':'+
CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,CAST(CONVERT(VARCHAR, DR_TimeIn,101)+' 11:59:59:000PM'AS DATETIME))%3600/60)
+':'+
CONVERT(VARCHAR(5),(DATEDIFF(SS,DR_TimeIn,CAST(CONVERT(VARCHAR, DR_TimeIn,101)+' 11:59:59:000PM'AS DATETIME))%60)),'0 ')
ELSE 'NOT CHECKED'
END
AS HOURS
FROM SG_Daily_Register
INNER JOIN
SG_Emp_Shift on SG_Daily_Register.DR_ShiftID=SG_Emp_Shift.ES_ShiftID
INNER JOIN SG_Emp_Master on SG_Daily_Register.DR_EmployeeID=SG_Emp_Master.EM_EmployeeID
INNER JOIN SG_Emp_Department on SG_Emp_Master.EM_DeptID=SG_Emp_Department.ED_DeptID
WHERE DR_EmployeeID=@EMPID AND CONVERT(VARCHAR,DR_TimeIn,101)BETWEEN @FROMDATE AND @TODATE
UNION
SELECT DR_EmployeeID as EMPID,EM_FirstName+EM_MiddleName+EM_LastName as EMPNAME,ED_Department as DEPARTMENT,
SUBSTRING(CONVERT(VARCHAR,ES_TimeIn,9),14,15)+'-'+SUBSTRING(CONVERT(VARCHAR,ES_TimeOut,9),14,15)as SHIFTTIME,
CASE WHEN ((CONVERT(VARCHAR,DR_TimeIn,101)=CONVERT(VARCHAR,DR_TimeOut,101))AND(SUBSTRING(CONVERT(VARCHAR,DR_TimeIn,9),14,15)>'11:59:59:000PM'))
THEN
ISNULL(CONVERT(VARCHAR,DR_TimeIn,107)+' 12:01:00:000AM','Not checked')
ELSE
ISNULL(CONVERT(VARCHAR,DR_TimeIn,109),'Not checked')
END
AS TIMEIN,
CASE WHEN(CONVERT(VARCHAR,DR_TimeIn,101)!=CONVERT(VARCHAR, DR_TimeOut,101))
THEN
ISNULL(CONVERT(VARCHAR,DR_TimeIn,107)+' 11:59:59:000PM','Not checked')
WHEN (CONVERT(VARCHAR,DR_TimeIn,101)=CONVERT(VARCHAR,DR_TimeOut,101))
THEN
ISNULL(CONVERT(VARCHAR,DR_TimeOut,109),'Not checked')
END
AS TIMEOUT,
CASE WHEN(CONVERT(VARCHAR, DR_TimeIn,101)=CONVERT(VARCHAR, DR_TimeOut,101))
THEN
ISNULL(CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,DR_TimeOut)/3600)
+':'+
CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,DR_TimeOut )%3600/60)
+':'+
CONVERT(VARCHAR(5),(DATEDIFF(SS,DR_TimeIn,DR_TimeOut)%60)),'0 ')
WHEN(CONVERT(VARCHAR, DR_TimeIn,101)!=CONVERT(VARCHAR, DR_TimeOut,101))
THEN
ISNULL(CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,CAST(CONVERT(VARCHAR,DR_TimeIn,101)+' 11:59:59:000PM'AS DATETIME))/3600)
+':'+
CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,CAST(CONVERT(VARCHAR, DR_TimeIn,101)+' 11:59:59:000PM'AS DATETIME))%3600/60)
+':'+
CONVERT(VARCHAR(5),(DATEDIFF(SS,DR_TimeIn,CAST(CONVERT(VARCHAR, DR_TimeIn,101)+' 11:59:59:000PM'AS DATETIME))%60)),'0 ')
ELSE 'NOT CHECKED'
END
AS HOURS
FROM SG_Daily_Register
INNER JOIN
SG_Emp_Shift on SG_Daily_Register.DR_ShiftID=SG_Emp_Shift.ES_ShiftID
INNER JOIN SG_Emp_Master on SG_Daily_Register.DR_EmployeeID=SG_Emp_Master.EM_EmployeeID
INNER JOIN SG_Emp_Department on SG_Emp_Master.EM_DeptID=SG_Emp_Department.ED_DeptID
WHERE DR_EmployeeID=@EMPID AND CONVERT(VARCHAR,DR_TimeIn,101)BETWEEN @FROMDATE AND @TODATE
)
|
|
|
|
|
Mate, please format the code because there are many smileys in your sql query.
|
|
|
|
|
Hi All,
I want to get all the values of a column as comma separated values in SQL Server. Can anybody help me writing the query for that.
Thanks in advance.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
Here is an example
DECLARE @String VARCHAR(1000)
SET @String = ''
SELECT @String = @String + ',' + Column1
FROM Table1
SELECT @String
Never underestimate the power of human stupidity
RAH
|
|
|
|
|