[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Trying to run DBCC SHRINKFILE from ADO Connection

Posted on 2006-07-07
21
Medium Priority
?
413 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

649 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