Solved

Trying to run DBCC SHRINKFILE from ADO Connection

Posted on 2006-07-07
21
401 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 15
  • 6
21 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17062127
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
ID: 17062290
the log name to the file in question. which I have confirmed via EM.
0
 

Author Comment

by:merydion
ID: 17062317
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17062339
can you please post it.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17062345
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
ID: 17062371
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
ID: 17062378
no special charactors... but I can try it...

The file name is text_DATE_log.ldf

0
 

Author Comment

by:merydion
ID: 17062397
nice idea... no go.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17062419
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
ID: 17062454
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
 

Author Comment

by:merydion
ID: 17062463
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
ID: 17062467
thanks for the ideas... I will keep playing with it...
0
 
LVL 143

Expert Comment

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

Author Comment

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

Author Comment

by:merydion
ID: 17062609
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
ID: 17062626
no open transactions, either.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 17062628
>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
ID: 17062659
ok, I will try that.
0
 

Author Comment

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

Author Comment

by:merydion
ID: 17062790
It is looking a lot like the FILE_ID is working.

Thanks!!!!
0
 

Author Comment

by:merydion
ID: 17084253
Yes, FILE_ID worked just fine.

Thanks a million!!!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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