Showing posts with label line. Show all posts
Showing posts with label line. Show all posts

Monday, March 26, 2012

Script to install northwind on SQL 2005

I tried to install the northwind script for 2000 and it failed in 2005 on
the first line of creating database.
Can someone send me the script for the sample northwind database on 2005 ,
the one that comes with the install ?
There's no 2005 version, but the originals can be downloaded from here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en
What is the error you get when installing, because as far as I know it
should work ok.
Cheers,
Paul Ibison

Script to identify line count in an procedure

Hi Guys,
Do any one of you have any scripts which return the procedure name and
number of lines for all procedures in a database.
Say I have a server with 1000 stored procedure,I need a script which return:
Procedure name Number of lines
-- --
Thanks in advance
HariI think this should do it:
SELECT O.name, SUM(LEN(text)-LEN(REPLACE(text,CHAR(13),'')))
FROM syscomments AS C
JOIN sysobjects AS O
ON C.id = O.id
WHERE O.xtype='P'
GROUP BY O.id, O.name
--
David Portas
--
Please reply only to the newsgroup
--|||Thanks a lot.
Regards
Hari
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:iMidnTtJieiJzlqiRVn-gQ@.giganews.com...
> I think this should do it:
> SELECT O.name, SUM(LEN(text)-LEN(REPLACE(text,CHAR(13),'')))
> FROM syscomments AS C
> JOIN sysobjects AS O
> ON C.id = O.id
> WHERE O.xtype='P'
> GROUP BY O.id, O.name
> --
> David Portas
> --
> Please reply only to the newsgroup
> --
>

Wednesday, March 21, 2012

Script Task - Am I leaving any resources open?

I've got a service that waits for a file to drop and then calls a ssis package that then gets a date from the first line of the file, sets it to a variable, then imports the rest of the file using the flat file import through a data flow task.

Occasionally the script task fails with this error message:

The script threw an exception: Access to the path 'C:\path\flatfile.txt' is denied.

Here is the code of my script:

Public Sub Main()
'
' Add your code here
'
Dim vars As Variables
Dts.VariableDispenser.LockOneForRead("User::FullFilePath", vars)

Dim filepath As String = vars("FullFilePath").Value.ToString()

vars.Unlock()

Dim file As File
Dim reader As StreamReader

reader = file.OpenText(filepath)

Dim line As String
line = reader.ReadLine()

reader.Close()

'MsgBox(line.Substring(29))

Dim asofdate As String
asofdate = line.Substring(29, 5)
asofdate = asofdate + "20" + line.Substring(34)

'MsgBox(asofdate)

Dim writeVars As Variables
Dts.VariableDispenser.LockOneForWrite("User::AsOfDate", writeVars)
writeVars(0).Value = asofdate

'MsgBox("done")

writeVars.Unlock()

Dts.TaskResult = Dts.Results.Success
End Sub

Does anyone see anything that I'm not. I believe i'm closing all necessary resources and streams. Does anyone have suggestions.

Thank you very much in advance.

Is it possible that your service calls the package multiple times simultaneously, or that the package could be executed before the drop is completed? The access violation in either of those cases would be due to the file still being locked by something else (e.g. the process writing the file, or the first package processing the file).

If neither are the case, then you could try a small re-write to see if it helps:

Replace:

Dim file As File
Dim reader As StreamReader

reader = file.OpenText(filepath)

Dim line As String
line = reader.ReadLine()

reader.Close()

With:

Dim line As String

Using reader as new StreamReader(filepath)

line = reader.Readline()

reader.Close()

End Using

HTH,

Patrik

|||Thanks for your response.

After banging my head against the table for a day i realized that the reason I was having issues is because the package in question was running as a service. The service was running under a particular user or usergroup. This usergroup was not one that had access to the files being run through my package, and therefore the package had its access deined by the OS.

In the interest of helping others, I'll leave this post up, even though it should have been one of the first things I tried.

Tuesday, March 20, 2012

Script line number

When you get a server error message referring to a line number in a
script, is there an easy way to jump to the correct line? It's not
easy to count down in a big script or when there is a lot of white
space.

In WordPerfect we had a linenum macro that allowed you to enter the
line number and it would jump to the line using the same counting
method as the interpreter that generated the error message. Is there
something similar with TSQL, or another way?

Kerry"Kerry" <kerrytforums@.hotmail.com> wrote:
> When you get a server error message referring to a line number in a
> script, is there an easy way to jump to the correct line? It's not
> easy to count down in a big script or when there is a lot of white
> space.
> In WordPerfect we had a linenum macro that allowed you to enter the
> line number and it would jump to the line using the same counting
> method as the interpreter that generated the error message. Is there
> something similar with TSQL, or another way?
> Kerry

Kerry,

That will depend on your editor... most editors (including Query Analyzer
with SQL Server 2000, Notepad in WinXP, and Visual Studio) have a function
for jumping to a specific line number. In most editors I've worked with on
Windows, it's usually ctrl-G

Craig|||In Query Analyzer, you can double-click on the error message in the
result pane to jump to the source line in question.

--
Hope this helps.

Dan Guzman
SQL Server MVP

--------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index...epartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
--------

"Kerry" <kerrytforums@.hotmail.com> wrote in message
news:6e61c2be.0311140759.25063405@.posting.google.c om...
> When you get a server error message referring to a line number in a
> script, is there an easy way to jump to the correct line? It's not
> easy to count down in a big script or when there is a lot of white
> space.
> In WordPerfect we had a linenum macro that allowed you to enter the
> line number and it would jump to the line using the same counting
> method as the interpreter that generated the error message. Is there
> something similar with TSQL, or another way?
> Kerry