Wednesday, March 7, 2012

Compacting a database MS SQL

Hi
for mS SQL 2000-2500
LDF and MDF files can be very very big, if I import the datas into a new database they can become 10 time smaller
is there a way to compact (reduce the MB) of a database ?
thank youLook up DBCC SHRINKDATABASE and DBCC SHRINKFILE in BOL.|||thank you !|||Do not shrink your databases. It can impair performance. SQL Server databases are not like Microsoft Access databases, and do not need to be regularly compacted.|||if I import the datas into a new database they can become 10 time smaller.

is there a way to compact (reduce the MB) of a database ?

Yeah, you can transfer required data in the new database - using DTS.

Accordingly, make changes in your application for accessing old data too.

Note : Before any action you need to deeply analyze pros & cons for the current issues as well as upcoming issues.

compacting / to repair base of data sql, using the msde

I am developing a project of the access for a friend, more I am with the
following doubts:
Does some exist it sorts things out of compacting / to repair base of data
sql, using the msde or the adp.?
MSDE databases do not require compacting. When updates or other changes are
made, the space freed when a row is deleted is reused automatically. For the
most part, MSDE/SQL Server databases are not subject to the file corruption
problems that are associated (from time-to-time ) with JET databases. There
are utilities (DBCC for one) that can be used to perform maintenance on the
database, but it's unusual to have to resort to these for smaller databases
as typically implemented with MSDE.
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Frank Dulk" <fdulk@.bol.com.br> wrote in message
news:%23ZUa0OKMEHA.2456@.TK2MSFTNGP12.phx.gbl...
> I am developing a project of the access for a friend, more I am with the
> following doubts:
> Does some exist it sorts things out of compacting / to repair base of data
> sql, using the msde or the adp.?
>

CompactDatabase in ASP with SQL Server Microsoft SQL Server Compact

I've been playing around with Microsoft SQL Server Compact Edition
v3.1 as a posible replacement for the SQL Server CE 2.0 (can't
remember exactly what the called it). Its working pretty well. I
was able to connect to the database using the same recordset object,
ADODB.RecordSet and connection object, ADOCE.Connection.3.1. However
where I've run into trouble is when I try to compact the database.
This code works on 2.0.

srcConn = "Provider=Microsoft." & "SQLServer" & ".OLEDB.CE.2.0;Data
Source=\myDB.sdf"
destConn = "Provider=Microsoft." & "SQLServer" & ".OLEDB.CE.2.0;Data
Source=\myDB.sdf"

Set DBEngine = CreateObject("SSCE.Engine.2.0")

DBEngine.CompactDatabase srcConn, destConn

But now when I try to run it vor v3.1

srcConn = "provider=microsoft.sqlserver.mobile.oledb.3.0;data
source=\myDB.sdf"
destConn = "provider=microsoft.sqlserver.mobile.oledb.3.0;data
source=\mDB1.sdf"

Set DBEngine = CreateObject("SSCE.Engine.3.0")

DBEngine.CompactDatabase srcConn, destConn

I get this error message:

Info: Object required: 'DBEngine'

As I understand it SSCE.Engine.3.0 is still an ActiveX
object. Is it no longer posible to run this directly from
asp?

Using SQL CE under asp.net has been blocked in SQL CE 3.1, see http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlceengine.aspx. Maybe this is what you are facing with asp as well. Have no idea how to do a

Code Snippet

AppDomain.CurrentDomain.SetData(

under asp classic.

Compact Tools Download Problem

When I try and download Sqlce30setupen.msi from the msdn site, I keep getting the install for the mobile tools. Can someone explain why this is happening. I am new to SQL compact and I am trying to go through the tutorial http://msdn2.microsoft.com/en-us/library/bb226707.aspx. This tutorial says the download should be for SQL Compact setup.

Thanks

Ryan

All downloads for SQL Compact Edition are available from http://www.microsoft.com/sql/editions/compact/downloads.mspx|||

Hi Ryan,

Are you having the same problem as me? When I download the setup file from the SQL Compact downloads url provided, it doesn't install the Compac Server Tools but tries to install "Microsoft SQL Server 2005 Mobile SP1 [ENU] Server Tools". I'm trying to install on Windows Server 2003. Interestingly if I run the same file on XP Pro it successfully installs the Compact Server Tools. I just added a new thread about this problem.

Regards,

Greg

Compact Tools Download Problem

When I try and download Sqlce30setupen.msi from the msdn site, I keep getting the install for the mobile tools. Can someone explain why this is happening. I am new to SQL compact and I am trying to go through the tutorial http://msdn2.microsoft.com/en-us/library/bb226707.aspx. This tutorial says the download should be for SQL Compact setup.

Thanks

Ryan

All downloads for SQL Compact Edition are available from http://www.microsoft.com/sql/editions/compact/downloads.mspx|||

Hi Ryan,

Are you having the same problem as me? When I download the setup file from the SQL Compact downloads url provided, it doesn't install the Compac Server Tools but tries to install "Microsoft SQL Server 2005 Mobile SP1 [ENU] Server Tools". I'm trying to install on Windows Server 2003. Interestingly if I run the same file on XP Pro it successfully installs the Compact Server Tools. I just added a new thread about this problem.

Regards,

Greg

compact sqlce database

Hi, there;

I got a SqlCe2.0 database here called JOB.sdf, size is 260K. When I tried to compact it, it took very long and that JOB.sdf.tmp was created with 27.7M!!!, I can still open table in the database, but I found that there is some invalid data (unreadable square boxes). It looks like database was corrupted. My application gave error:

Error Code: 80040E14
Message : The OLE DB Execute method failed. The SQL statement is not valid. [,,,SQL statement,,]
Minor Err.: 28560
Source : Microsoft SQL Server 2000 Windows CE Edition
Error Code: 80040E14
Message : Line 1: Incorrect syntax near 'à ??€’‰ì±′ê???????ê¢?è???3?'.
Minor Err.: 170
Source : Microsoft OLE DB Provider for SQL Server
Error Code: 80040E14
Message : Unclosed quotation mark before the character string 'à ??€’‰ì±′ê???????ê¢?è???3?'.
Minor Err.: 105
Source : Microsoft OLE DB Provider for SQL Server</E>

Note: " " is displayed as "SOHSOH....." with black background.

Apart from compacting database, is there manual job or tool we can do/use to fix a corrupted database caused by power failure? (e.x: all data saved successfully before power failure)?

Thanks

HI,

have you tried to use newer SQLCE engine with existing corrupted database ?

Although I had never tried it yet, I think that when you try "Verify" and "Repair"

features of SQLCE, you can safely survive most of your database. Go and

download SQL CE 3.1 desktop engine and tools, its even good to work with it :-)

hope it helps,

Petr

|||

Thanks.

How can get the newer SQLCE engine? Can that be run at desktop without a device?

I have quite a bit corrupted databases whih is a disaster now!

|||

Yes, you can download all engines withing SDK from here:

http://www.microsoft.com/sql/editions/compact/default.mspx

resp.

http://www.microsoft.com/downloads/details.aspx?FamilyId=E9AA3F8D-363D-49F3-AE89-64E1D149E09B&displaylang=en

may be other tools from this web may help you too.

Without VS2005, you can manage database through

free SQLServer Management Studio Express

http://www.microsoft.com/downloads/details.aspx?FamilyId=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796&DisplayLang=en

I dont know if is possible to verify/repair from this gui app, but at least you can

build small C# or VB.NET desktop project against new engine, using your corrupted database

and try verify/repair methods.

Petr

|||

:-( excuse me, SQLSerer Management Studio must be full, not only Express !!!

This is very big download, so it may dissappoint you.

BTW, best is to do small project itself and use code :-)

Petr

|||Thank you. I will give it a try.

Compact Sql Mobile 3.0 DataBase in C++/OLE DB ?

Hello,

I'm porting my C++ (EVC3) application from Sql CE 2.0 to Sql Mobile 3.0

(with OLE DB). To compact a 2.0 database, i used ISSCECompact interface.

But it doesn't exists with the new version. I've only found C#

and VB.Net samples in MSDN ...

Thanks in advance.

Have you had a chance to look at: http://msdn2.microsoft.com/en-us/library/ms174034(en-US,SQL.90).aspx

Thanks,

Laxmi NRO, MSFT, SQL Mobile, Microsoft Corporation

|||

#include "ca_merge30.h"
#include <stdio.h>

void ErrorPrint() ;

#define VerifyResult(x) hr=x;\
if(FAILED(hr)) { \
printf("Failed : HR : %x\n",hr); \
printf("at : %d \n",__LINE__); \
ErrorPrint(); \
goto Exit; \
}
#define RELEASE(x) if(NULL!=x)x->Release();

extern "C" int __cdecl wmain(){

HRESULT hr = NOERROR;
ISSCEEngine *pISSCEEngine = NULL;
VerifyResult(CoInitialize(NULL));
VerifyResult(CoCreateInstance(CLSID_Engine, NULL, CLSCTX_INPROC_SERVER,
IID_ISSCEEngine, (void**)&pISSCEEngine));

WCHAR *wszSrc=L"Data Source = src.sdf";
WCHAR *wszDst=L"Data Source = dst.sdf";
VerifyResult(pISSCEEngine->CompactDatabase(wszSrc, wszDst));


Exit:
RELEASE(pISSCEEngine);
CoUninitialize();
return hr;
}

void ErrorPrint()
{
LPVOID lpMsgBuf;
DWORD dw = GetLastError();

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );

printf( "Failed with error %d: %ls",
dw, lpMsgBuf);

LocalFree(lpMsgBuf);
}

Hope this helps! Thanks,

Laxmi NRO, MSFT, SQL Mobile, Microsoft Corporation

(Sample By: BalaDutt, MSFT, SQL Mobile, Microsoft Corporation)

|||Many thanks ! It's exactly what i needed !|||

Glad that I could help you.

Thanks,

Laxmi Narsimha Rao ORUGANTI, MSFT, SQL Mobile, Microsoft Corporation

|||

This helped me as well, thanks. But I also cannot find any reference material for how to perform a "Verify" DB as advertised in the Documentation for SQL Server Mobile Edition.

The docs have a sample in C#, but nothing for OLD DB in C++.

Does anyone know how to do this?