?
Solved

Trying to run DBCC SHRINKFILE from ADO Connection

Posted on 2006-07-07
21
Medium Priority
?
412 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
Independent Software Vendors: 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 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