Showing posts with label folder. Show all posts
Showing posts with label folder. Show all posts

Tuesday, March 20, 2012

Could you tell me the VB code to check the file size in a folder and mail to xyz@abc.com automat

Dear all,

Could you tell me which code of vb scrip that i can check file size as follow ?

Dim FSO, Fyl
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fyl = CreateObject("File")

If FSO.FileExists("C:\temp\lcbseg.log") Then
Set Fyl = FSO.GetFile("C:\temp\lcbseg.log")
If Fyl.Size > 0 Then
Main = DTSStepScriptResult_ExecuteTask
Else
Main = DTSStepScriptResult_DontExecuteTask
End If
End if

Thanks

Best regards,

Kusuma

You need to do this in two stages, since there is no workflow script anymore.

Here is a sample for nthe Script Task. It uses a variable called FileSize, into which it stores the file size, surpirse!

Public Sub Main()

Dim info As System.IO.FileInfo = New System.IO.FileInfo("C:\File.txt")

Dim variables As New Variables

Dts.VariableDispenser.LockOneForWrite("FileSize", variables)

variables(0).Value = info.Length

variables.Unlock()

Dts.TaskResult = Dts.Results.Success

End Sub

Now you would use a precedenc constraint from the sript task to the next task, but be sure to include an expression. Double-click to get the UI, and try and expression like this-

@.[Use::FileSize] > 0

|||

I've tried to follow your code DarrenSQLIS, but it has the error "FileSize" for read/write access with error 0xC0010001 "The variable cannot be found. how can i fix this problem?

So i've some questions where can i declare FileSize variable. It's on SSIS menu=> varible,isn't it? and what's type of FileSize variable. For next what's property of expresstion to use @.[Use::FileSize] > 0.

Many thanks.

Best Regards,

Kusuma

|||I know you asked how do check for a file size equal to non zero in a script task, which can certainly be done with a script task as Darren illustrates.

Another technique for checking file existence and size simultaneously is use of "WMI Data Reader Task" with WQL. Use of the WMI data reader task will require a WMI connection manager, which is quick simple to configure, and available through the task's UI.

For example, the following WQL query checks for the existence and size of c:\boot.ini. simultaneously.

Select FileSize From CIM_Datafile Where Name = 'C:\\boot.ini'

After the WMI task, a downstream task can constrained by the following expression, which evaluates to true only for an existent, non zero byte file.

@.FileLength > "0\r\n"

NOTE, in this case, @.FileLength is a string variable, unlike the script task case. The reason the variable for file size is a string rather than a uint64 is that the WMI Data Reader task writes string and/or object variable types. The backslash is a special character to WMI, and as such is doubled up (escaped) in the WQL query.
|||

KUS wrote:

Dear all,

Could you tell me which code of vb scrip that i can check file size as follow ?

Dim FSO, Fyl
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fyl = CreateObject("File")

If FSO.FileExists("C:\temp\lcbseg.log") Then
Set Fyl = FSO.GetFile("C:\temp\lcbseg.log")
If Fyl.Size > 0 Then
Main = DTSStepScriptResult_ExecuteTask
Else
Main = DTSStepScriptResult_DontExecuteTask
End If
End if

Thanks

Best regards,

Kusuma

|||Hey hi . Could you tell me a VB code so that I can check a file size in a folder and mail to abc@.xyz.com if the file size is less than 10MB?|||First of all read the code above, it shows you how to get the file size into a variable. Then use an SMTP Send Mail Task to send the mail. To restrict the email to only files < 10MB, add an expression on the precendence constraint between the Script Task and Mail Task, @.Var < 10000sql

Monday, March 19, 2012

Could not locate entry in sysdatabases for database

I have two database, let's call them DbA and DbB. DbA was already in the
right folder, but DbB wasn't. So I detached DbB, moved it to the new folder
and reattached it. Everything seems to be working (I can see the database
from Management Studio Express (MSE), the website can access it just fine)
except when I try to backup DbB. Backing up from MSE works without a
problem, however if I try to run this query:
BACKUP DATABASE [DbB] TO DISK = N'C:\WebDb.backup\DbB\DbB.bak' WITH
NOFORMAT, NOINIT, NAME = N'DbB-Full Database Backup', SKIP, NOREWIND,
NOUNLOAD, STATS = 10
GO
with this sqlcmd.exe command:
sqlcmd -i c:\WebBackupScripts\BkDbB.sql -o c:\WebBackupScripts\BkDbB.sql.txt
I get this:
Msg 911, Level 16, State 1, Server DEV, Line 1
Could not locate entry in sysdatabases for database 'DbB'. No entry found
with that name. Make sure that the name is entered correctly.
Msg 3013, Level 16, State 1, Server DEV, Line 1
BACKUP DATABASE is terminating abnormally.
The exact same query runs fine from MSE, but fails when ran from sqlcmd --
the sql was actually generated by MSE. A similar query, but for DbA works
fine from sqlcmd. The only thing that I can think of that's different is
that I've attached/reattached DbB. I've searched the net, but nothing
really helped. Any suggestions?
Thank you,
Peter.
Hello,
Do you have multiple instances of SQL Server in the same server. Just issue
the -S Servername parameter along with
SQLCMD statement and try.
Thanks
Hari
"Peter Zolja" <x@.x.com> wrote in message
news:eYTyx4uPHHA.2140@.TK2MSFTNGP03.phx.gbl...
>I have two database, let's call them DbA and DbB. DbA was already in the
>right folder, but DbB wasn't. So I detached DbB, moved it to the new folder
>and reattached it. Everything seems to be working (I can see the database
>from Management Studio Express (MSE), the website can access it just fine)
>except when I try to backup DbB. Backing up from MSE works without a
>problem, however if I try to run this query:
> BACKUP DATABASE [DbB] TO DISK = N'C:\WebDb.backup\DbB\DbB.bak' WITH
> NOFORMAT, NOINIT, NAME = N'DbB-Full Database Backup', SKIP, NOREWIND,
> NOUNLOAD, STATS = 10
> GO
> with this sqlcmd.exe command:
> sqlcmd -i c:\WebBackupScripts\BkDbB.sql -o
> c:\WebBackupScripts\BkDbB.sql.txt
> I get this:
> Msg 911, Level 16, State 1, Server DEV, Line 1
> Could not locate entry in sysdatabases for database 'DbB'. No entry found
> with that name. Make sure that the name is entered correctly.
> Msg 3013, Level 16, State 1, Server DEV, Line 1
> BACKUP DATABASE is terminating abnormally.
>
> The exact same query runs fine from MSE, but fails when ran from sqlcmd --
> the sql was actually generated by MSE. A similar query, but for DbA works
> fine from sqlcmd. The only thing that I can think of that's different is
> that I've attached/reattached DbB. I've searched the net, but nothing
> really helped. Any suggestions?
> Thank you,
> Peter.
>
|||> Do you have multiple instances of SQL Server in the same server. Just
> issue the -S Servername parameter along with
> SQLCMD statement and try.
Ahaaaaaa... right on the money :-) I have SQL 2005 Express and MSDE on the
same machine. SQL2005 is installed under the SQLExpress instance. So adding
"-S .\SQLExpress" to the sqlcmd parameter list made it work. I'm still
puzzled why that wasn't required for DbA... could it be that DbA is the
"default" database?
In any case, thanks a LOT for you help!
|||Hello,
Yes, thats the default instance.
You will have to give the server instance name if you have multiple servers
in one machine.
Thanks
Hari
"Peter Zolja" <x@.x.com> wrote in message
news:%23tu1GEvPHHA.1248@.TK2MSFTNGP03.phx.gbl...
> Ahaaaaaa... right on the money :-) I have SQL 2005 Express and MSDE on the
> same machine. SQL2005 is installed under the SQLExpress instance. So
> adding "-S .\SQLExpress" to the sqlcmd parameter list made it work. I'm
> still puzzled why that wasn't required for DbA... could it be that DbA is
> the "default" database?
> In any case, thanks a LOT for you help!
>
|||Thanks to Hari! You're a life saver. Where were you 5 hours ago?
From http://www.developmentnow.com/g/118_2007_1_0_0_928077/Could-not-locate-entry-in-sysdatabases-for-database.htm
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Sunday, March 11, 2012

Could not locate entry in sysdatabases for database

I have two database, let's call them DbA and DbB. DbA was already in the
right folder, but DbB wasn't. So I detached DbB, moved it to the new folder
and reattached it. Everything seems to be working (I can see the database
from Management Studio Express (MSE), the website can access it just fine)
except when I try to backup DbB. Backing up from MSE works without a
problem, however if I try to run this query:
BACKUP DATABASE [DbB] TO DISK = N'C:\WebDb.backup\DbB\DbB.bak' WITH
NOFORMAT, NOINIT, NAME = N'DbB-Full Database Backup', SKIP, NOREWIND,
NOUNLOAD, STATS = 10
GO
with this sqlcmd.exe command:
sqlcmd -i c:\WebBackupScripts\BkDbB.sql -o c:\WebBackupScripts\BkDbB.sql.txt
I get this:
Msg 911, Level 16, State 1, Server DEV, Line 1
Could not locate entry in sysdatabases for database 'DbB'. No entry found
with that name. Make sure that the name is entered correctly.
Msg 3013, Level 16, State 1, Server DEV, Line 1
BACKUP DATABASE is terminating abnormally.
The exact same query runs fine from MSE, but fails when ran from sqlcmd --
the sql was actually generated by MSE. A similar query, but for DbA works
fine from sqlcmd. The only thing that I can think of that's different is
that I've attached/reattached DbB. I've searched the net, but nothing
really helped. Any suggestions?
Thank you,
Peter.Hello,
Do you have multiple instances of SQL Server in the same server. Just issue
the -S Servername parameter along with
SQLCMD statement and try.
Thanks
Hari
"Peter Zolja" <x@.x.com> wrote in message
news:eYTyx4uPHHA.2140@.TK2MSFTNGP03.phx.gbl...
>I have two database, let's call them DbA and DbB. DbA was already in the
>right folder, but DbB wasn't. So I detached DbB, moved it to the new folder
>and reattached it. Everything seems to be working (I can see the database
>from Management Studio Express (MSE), the website can access it just fine)
>except when I try to backup DbB. Backing up from MSE works without a
>problem, however if I try to run this query:
> BACKUP DATABASE [DbB] TO DISK = N'C:\WebDb.backup\DbB\DbB.bak' WITH
> NOFORMAT, NOINIT, NAME = N'DbB-Full Database Backup', SKIP, NOREWIND,
> NOUNLOAD, STATS = 10
> GO
> with this sqlcmd.exe command:
> sqlcmd -i c:\WebBackupScripts\BkDbB.sql -o
> c:\WebBackupScripts\BkDbB.sql.txt
> I get this:
> Msg 911, Level 16, State 1, Server DEV, Line 1
> Could not locate entry in sysdatabases for database 'DbB'. No entry found
> with that name. Make sure that the name is entered correctly.
> Msg 3013, Level 16, State 1, Server DEV, Line 1
> BACKUP DATABASE is terminating abnormally.
>
> The exact same query runs fine from MSE, but fails when ran from sqlcmd --
> the sql was actually generated by MSE. A similar query, but for DbA works
> fine from sqlcmd. The only thing that I can think of that's different is
> that I've attached/reattached DbB. I've searched the net, but nothing
> really helped. Any suggestions?
> Thank you,
> Peter.
>|||> Do you have multiple instances of SQL Server in the same server. Just
> issue the -S Servername parameter along with
> SQLCMD statement and try.
Ahaaaaaa... right on the money :-) I have SQL 2005 Express and MSDE on the
same machine. SQL2005 is installed under the SQLExpress instance. So adding
"-S .\SQLExpress" to the sqlcmd parameter list made it work. I'm still
puzzled why that wasn't required for DbA... could it be that DbA is the
"default" database?
In any case, thanks a LOT for you help!|||Hello,
Yes, thats the default instance.
You will have to give the server instance name if you have multiple servers
in one machine.
Thanks
Hari
"Peter Zolja" <x@.x.com> wrote in message
news:%23tu1GEvPHHA.1248@.TK2MSFTNGP03.phx.gbl...
>> Do you have multiple instances of SQL Server in the same server. Just
>> issue the -S Servername parameter along with
>> SQLCMD statement and try.
> Ahaaaaaa... right on the money :-) I have SQL 2005 Express and MSDE on the
> same machine. SQL2005 is installed under the SQLExpress instance. So
> adding "-S .\SQLExpress" to the sqlcmd parameter list made it work. I'm
> still puzzled why that wasn't required for DbA... could it be that DbA is
> the "default" database?
> In any case, thanks a LOT for you help!
>|||Thanks to Hari! You're a life saver. Where were you 5 hours ago
From http://www.developmentnow.com/g/118_2007_1_0_0_928077/Could-not-locate-entry-in-sysdatabases-for-database.ht
Posted via DevelopmentNow.com Group
http://www.developmentnow.com

Could not locate entry in sysdatabases for database

I have two database, let's call them DbA and DbB. DbA was already in the
right folder, but DbB wasn't. So I detached DbB, moved it to the new folder
and reattached it. Everything seems to be working (I can see the database
from Management Studio Express (MSE), the website can access it just fine)
except when I try to backup DbB. Backing up from MSE works without a
problem, however if I try to run this query:
BACKUP DATABASE [DbB] TO DISK = N'C:\WebDb.backup\DbB\DbB.bak' WITH
NOFORMAT, NOINIT, NAME = N'DbB-Full Database Backup', SKIP, NOREWIND,
NOUNLOAD, STATS = 10
GO
with this sqlcmd.exe command:
sqlcmd -i c:\WebBackupScripts\BkDbB.sql -o c:\WebBackupScripts\BkDbB.sql.txt
I get this:
Msg 911, Level 16, State 1, Server DEV, Line 1
Could not locate entry in sysdatabases for database 'DbB'. No entry found
with that name. Make sure that the name is entered correctly.
Msg 3013, Level 16, State 1, Server DEV, Line 1
BACKUP DATABASE is terminating abnormally.
The exact same query runs fine from MSE, but fails when ran from sqlcmd --
the sql was actually generated by MSE. A similar query, but for DbA works
fine from sqlcmd. The only thing that I can think of that's different is
that I've attached/reattached DbB. I've searched the net, but nothing
really helped. Any suggestions?
Thank you,
Peter.Hello,
Do you have multiple instances of SQL Server in the same server. Just issue
the -S Servername parameter along with
SQLCMD statement and try.
Thanks
Hari
"Peter Zolja" <x@.x.com> wrote in message
news:eYTyx4uPHHA.2140@.TK2MSFTNGP03.phx.gbl...
>I have two database, let's call them DbA and DbB. DbA was already in the
>right folder, but DbB wasn't. So I detached DbB, moved it to the new folder
>and reattached it. Everything seems to be working (I can see the database
>from Management Studio Express (MSE), the website can access it just fine)
>except when I try to backup DbB. Backing up from MSE works without a
>problem, however if I try to run this query:
> BACKUP DATABASE [DbB] TO DISK = N'C:\WebDb.backup\DbB\DbB.bak' WITH
> NOFORMAT, NOINIT, NAME = N'DbB-Full Database Backup', SKIP, NOREWIND,
> NOUNLOAD, STATS = 10
> GO
> with this sqlcmd.exe command:
> sqlcmd -i c:\WebBackupScripts\BkDbB.sql -o
> c:\WebBackupScripts\BkDbB.sql.txt
> I get this:
> Msg 911, Level 16, State 1, Server DEV, Line 1
> Could not locate entry in sysdatabases for database 'DbB'. No entry found
> with that name. Make sure that the name is entered correctly.
> Msg 3013, Level 16, State 1, Server DEV, Line 1
> BACKUP DATABASE is terminating abnormally.
>
> The exact same query runs fine from MSE, but fails when ran from sqlcmd --
> the sql was actually generated by MSE. A similar query, but for DbA works
> fine from sqlcmd. The only thing that I can think of that's different is
> that I've attached/reattached DbB. I've searched the net, but nothing
> really helped. Any suggestions?
> Thank you,
> Peter.
>|||> Do you have multiple instances of SQL Server in the same server. Just
> issue the -S Servername parameter along with
> SQLCMD statement and try.
Ahaaaaaa... right on the money :-) I have SQL 2005 Express and MSDE on the
same machine. SQL2005 is installed under the SQLExpress instance. So adding
"-S .\SQLExpress" to the sqlcmd parameter list made it work. I'm still
puzzled why that wasn't required for DbA... could it be that DbA is the
"default" database?
In any case, thanks a LOT for you help!|||Hello,
Yes, thats the default instance.
You will have to give the server instance name if you have multiple servers
in one machine.
Thanks
Hari
"Peter Zolja" <x@.x.com> wrote in message
news:%23tu1GEvPHHA.1248@.TK2MSFTNGP03.phx.gbl...
> Ahaaaaaa... right on the money :-) I have SQL 2005 Express and MSDE on the
> same machine. SQL2005 is installed under the SQLExpress instance. So
> adding "-S .\SQLExpress" to the sqlcmd parameter list made it work. I'm
> still puzzled why that wasn't required for DbA... could it be that DbA is
> the "default" database?
> In any case, thanks a LOT for you help!
>|||Thanks to Hari! You're a life saver. Where were you 5 hours ago?
From http://www.developmentnow.com/g/118...or-database.htm
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com