Solved

Trying to run DBCC SHRINKFILE from ADO Connection

Posted on 2006-07-07
21
362 Views
Last Modified: 2013-12-25
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!

0
Comment
Question by:merydion
  • 15
  • 6
21 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
can you show the query you run to fine the log file name?

what does this query return:
select * from sysfiles

0
 

Author Comment

by:merydion
Comment Utility
the log name to the file in question. which I have confirmed via EM.
0
 

Author Comment

by:merydion
Comment Utility
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
can you please post it.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
 

Author Comment

by:merydion
Comment Utility
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
 

Author Comment

by:merydion
Comment Utility
no special charactors... but I can try it...

The file name is text_DATE_log.ldf

0
 

Author Comment

by:merydion
Comment Utility
nice idea... no go.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
 

Author Comment

by:merydion
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:merydion
Comment Utility
oh, and it's the logical name, not the physical file name. I did the [] with no change in the problem.
0
 

Author Comment

by:merydion
Comment Utility
thanks for the ideas... I will keep playing with it...
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
single quotes any better:
oConn.Execute "DBCC SHRINKFILE ('" & sLogFileName & "',10)"
0
 

Author Comment

by:merydion
Comment Utility
hm... I will let you know. I just rebooted... cause none are working now!
0
 

Author Comment

by:merydion
Comment Utility
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
 

Author Comment

by:merydion
Comment Utility
no open transactions, either.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
>the shrinkfile is taking the logical name
can you try to use the file_id instead? dbcc shrinkfile can also take that one...
0
 

Author Comment

by:merydion
Comment Utility
ok, I will try that.
0
 

Author Comment

by:merydion
Comment Utility
to use the File_ID, should I issue a USE Db command first?
0
 

Author Comment

by:merydion
Comment Utility
It is looking a lot like the FILE_ID is working.

Thanks!!!!
0
 

Author Comment

by:merydion
Comment Utility
Yes, FILE_ID worked just fine.

Thanks a million!!!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now