Trying to run DBCC SHRINKFILE from ADO Connection

And the application kicks an error indicating the _log file wasn't found.

Here is the rub, I have 5 databases. The other four run a-ok. I can also run the shrinkfile command in Query Analyzer, but it simply will not run in my VB application (it's a database copy utility).

Thoughts?

This is the code I am running:

Call CreateConnection(oConn, 600)
oConn.Execute "DBCC SHRINKFILE (" & sLogFileName & ",10)"
Call DestroyConnection(oConn)

I run a backup with truncate only before I do this... and the whole process is dependant on the size of the log file being over 12800 units. I get the log file name from the size check query.

It kicks back error number -2147217900. File not found. It is there! I have checked the DB properties in Enterprise Manager!

merydionAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
>the shrinkfile is taking the logical name
can you try to use the file_id instead? dbcc shrinkfile can also take that one...
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
can you show the query you run to fine the log file name?

what does this query return:
select * from sysfiles

0
 
merydionAuthor Commented:
the log name to the file in question. which I have confirmed via EM.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
merydionAuthor Commented:
a bit more detail: The application does a "copy" of a database, meaning, I do a backup and restore, and the restore renames the file.

The shrinkfile is being done on the original source db, in an attempt to be sure it isn't too big before the copy is made.

I am going to test this against one of the copies...
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
can you please post it.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
To explain: I assume that the name has a special character ...
in which case the following would solve the issue:
oConn.Execute "DBCC SHRINKFILE ([" & sLogFileName & "],10)"
0
 
merydionAuthor Commented:
I ran this against the various copies, and the copies don't work... none of them do. But the data is all present and the file exists where it is supposed to.
0
 
merydionAuthor Commented:
no special charactors... but I can try it...

The file name is text_DATE_log.ldf

0
 
merydionAuthor Commented:
nice idea... no go.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_dbcc_8b51.asp
<...>
file_name
Is the logical name of the file shrunk. File names must conform to the rules for identifiers. For more information, see Using Identifiers.
<...>

text_DATE_log.ldf seems to me to be the physical name, not the logical one?
if it IS the logical one, then [] will help.
if it is the physical one, well, you got the wrong value.
0
 
merydionAuthor Commented:
yea, but explain why the exact same file name works when I run it in Query Analyzer? Or why the other 4 dbs work fine?

this makes little sense...
0
 
merydionAuthor Commented:
oh, and it's the logical name, not the physical file name. I did the [] with no change in the problem.
0
 
merydionAuthor Commented:
thanks for the ideas... I will keep playing with it...
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
single quotes any better:
oConn.Execute "DBCC SHRINKFILE ('" & sLogFileName & "',10)"
0
 
merydionAuthor Commented:
hm... I will let you know. I just rebooted... cause none are working now!
0
 
merydionAuthor Commented:
nope.

AFAIK, the shrinkfile is taking the logical name and using that to re-hit the sysfiles to get the physical location... what bothers me is that those files are present.

Oh, I checked the error log... it shows where the files had their logs backed up and truncated, but there are no error codes.

dollars to donuts tells me if I run this in QA, it will work like a champ.
0
 
merydionAuthor Commented:
no open transactions, either.
0
 
merydionAuthor Commented:
ok, I will try that.
0
 
merydionAuthor Commented:
to use the File_ID, should I issue a USE Db command first?
0
 
merydionAuthor Commented:
It is looking a lot like the FILE_ID is working.

Thanks!!!!
0
 
merydionAuthor Commented:
Yes, FILE_ID worked just fine.

Thanks a million!!!
0
All Courses

From novice to tech pro — start learning today.