显示标签为“cant”的博文。显示所有博文
显示标签为“cant”的博文。显示所有博文

2012年3月8日星期四

Disarming IDENTITY generation

Ok, suppose I have created a new table with an Identity column, but I want to load the table from an existing table and I can’t let SQL Ev reset the Identity values. In SQL Server I can turn off Identity generation using

SET IDENTITY_INSERT biblio.dbo.authors OFF

Is there an equivalent in SQL Ev?

My next question is (if this does not work), can I use ALTER TABLE to disarm the Identity value and re-arm it after the load?

Bill,

no, you cannot disable the generation of identity values as you insert records into a table with an identity column, but you can alter the seed and increment values on the column using ALTER TABLE ALTER COLUMN standard syntax. For example, if the rows you are putting into the empty table begin with identity values starting at 1000, just create the table with this identity columns seed set to 1000.

if you want to know the last value of an identity column after one or more inserts, select the @.@.IDENTITY function against the table.

if there is any chance this table will be in an RDA or merge replication synchronization relationship with a server, I would strongly suggest you use uniqueidentifiers instead of identity columns on your table. this will avoid a lot of admin and possible conflicts if you are in a multi-user environment.

as I follow your posts, it sure sounds to me like you are in the process of creating a starter SQL Everywhere database based on a server-side database. Have you considered just setting up a quick merge replication and using the option to have the SQL Everywhere database created dynamically from the server upon initial replication (AddSubscription(AddOption.CreateDatabase))? I have posted a lot of info on this and done a few MSDN webcasts on the topic, so search this forum for 'starter database' for more details. this would solve your issues with identity column values and also with FK creation.

Darren

|||

Actually, I'm trying to write an EBook to supplement my new Hitchhiker's Guide to Visual Studio and SQL Server book. So far, all I've found is a million issues...

The current problem is that the ID values in the rows on the source table are joined logically to other tables. That is, the Author_ID is in the Title_Author table so it can't be arbitrarily changed without changing the other table(s) that are linked to the Author_ID. The same goes for the other tables. This makes it tough to load Identity values at all into a SQLCE database--I guess I'll have to give up on that approach. However, I don't see that using uniqueidentifiers will help unless I can go back and rebuild the PK/FK relationships on the source tables using them (a PIA).

Yes, I can see that I need to go back two squares and try to build a replication scenario.

My inital tests with SSIS did not work so that's a non-starter. I found that the host database uses datatypes not supported by SQL Ev including VarChar and Timestamp which chokes SSIS.

I expect I'll have to create a custom server-side database that's specifically designed to deal with all of these issues.

I'll check out your content. I would like to check out the SQL CF MVP pages (I'm also an MVP) can you drop a private note pointing to where you hang out?

Bill

|||

sure Bill - feel free to shoot me an email - I'm googlable and in the MVP directory as well.

-ds

|||

My two cents... With SQL CE 2.0 you could actually overwite the identity values through the OLE DB provider (a bit like in Access but this engine goes a bit further and even updates the seed). Microsoft dropped this behavior with SQL Mobile and this posed a big challenge for my database copy / sync tools. What now? Turns out, the only solution is to ALTER TABLE and set the seed to the next value to be inserted for every row. You will also have to reset the identity properties to what they are supposed to be at the end of the export procedure. To make all of this work, you also have to make sure you close the base table cursor (if any) before altering the identity value. This means more work for a SqlCeResultSet, but not for an INSERT command.

It's a lot of development work but the code is not slower than in the SQL CE 2.0 case, so it's quite workable and it is the solution I actually adopted.

|||

Interesting solution. I guess it would only be more convoluted if it involved live chickens.

I'm not sure I'll recommend this in my book other than mention it as an alternative...

Thanks

|||

I don't think that was going to work because the SQL Server 2005 Mobile Edition does not support Alter table as a SQL Statement .At leat I could not make it work.Right now I'm stucked on that problem and I would like to read other opinions

Nelson

|||

I would like to know how can I make it work using the alter table statement since I tried and it did not work.I tried using the SQL Server Editor in Visual Studio and at runtime .None of those options seems to work.

Thanks in advance

Disarming IDENTITY generation

Ok, suppose I have created a new table with an Identity column, but I want to load the table from an existing table and I can’t let SQL Ev reset the Identity values. In SQL Server I can turn off Identity generation using

SET IDENTITY_INSERT biblio.dbo.authors OFF

Is there an equivalent in SQL Ev?

My next question is (if this does not work), can I use ALTER TABLE to disarm the Identity value and re-arm it after the load?

Bill,

no, you cannot disable the generation of identity values as you insert records into a table with an identity column, but you can alter the seed and increment values on the column using ALTER TABLE ALTER COLUMN standard syntax. For example, if the rows you are putting into the empty table begin with identity values starting at 1000, just create the table with this identity columns seed set to 1000.

if you want to know the last value of an identity column after one or more inserts, select the @.@.IDENTITY function against the table.

if there is any chance this table will be in an RDA or merge replication synchronization relationship with a server, I would strongly suggest you use uniqueidentifiers instead of identity columns on your table. this will avoid a lot of admin and possible conflicts if you are in a multi-user environment.

as I follow your posts, it sure sounds to me like you are in the process of creating a starter SQL Everywhere database based on a server-side database. Have you considered just setting up a quick merge replication and using the option to have the SQL Everywhere database created dynamically from the server upon initial replication (AddSubscription(AddOption.CreateDatabase))? I have posted a lot of info on this and done a few MSDN webcasts on the topic, so search this forum for 'starter database' for more details. this would solve your issues with identity column values and also with FK creation.

Darren

|||

Actually, I'm trying to write an EBook to supplement my new Hitchhiker's Guide to Visual Studio and SQL Server book. So far, all I've found is a million issues...

The current problem is that the ID values in the rows on the source table are joined logically to other tables. That is, the Author_ID is in the Title_Author table so it can't be arbitrarily changed without changing the other table(s) that are linked to the Author_ID. The same goes for the other tables. This makes it tough to load Identity values at all into a SQLCE database--I guess I'll have to give up on that approach. However, I don't see that using uniqueidentifiers will help unless I can go back and rebuild the PK/FK relationships on the source tables using them (a PIA).

Yes, I can see that I need to go back two squares and try to build a replication scenario.

My inital tests with SSIS did not work so that's a non-starter. I found that the host database uses datatypes not supported by SQL Ev including VarChar and Timestamp which chokes SSIS.

I expect I'll have to create a custom server-side database that's specifically designed to deal with all of these issues.

I'll check out your content. I would like to check out the SQL CF MVP pages (I'm also an MVP) can you drop a private note pointing to where you hang out?

Bill

|||

sure Bill - feel free to shoot me an email - I'm googlable and in the MVP directory as well.

-ds

|||

My two cents... With SQL CE 2.0 you could actually overwite the identity values through the OLE DB provider (a bit like in Access but this engine goes a bit further and even updates the seed). Microsoft dropped this behavior with SQL Mobile and this posed a big challenge for my database copy / sync tools. What now? Turns out, the only solution is to ALTER TABLE and set the seed to the next value to be inserted for every row. You will also have to reset the identity properties to what they are supposed to be at the end of the export procedure. To make all of this work, you also have to make sure you close the base table cursor (if any) before altering the identity value. This means more work for a SqlCeResultSet, but not for an INSERT command.

It's a lot of development work but the code is not slower than in the SQL CE 2.0 case, so it's quite workable and it is the solution I actually adopted.

|||

Interesting solution. I guess it would only be more convoluted if it involved live chickens.

I'm not sure I'll recommend this in my book other than mention it as an alternative...

Thanks

|||

I don't think that was going to work because the SQL Server 2005 Mobile Edition does not support Alter table as a SQL Statement .At leat I could not make it work.Right now I'm stucked on that problem and I would like to read other opinions

Nelson

|||

I would like to know how can I make it work using the alter table statement since I tried and it did not work.I tried using the SQL Server Editor in Visual Studio and at runtime .None of those options seems to work.

Thanks in advance

2012年2月24日星期五

DisableNetAccess

Windows98 machine and when installing MSDE we (our customer) gets an error
on DisableNetAccess. I have no idea what they should do and I can't find
anything in google with the word disablenetaccess so I'm hoping somebody out
there has some info. Below is the relevant info from the log file when
trying to install.
MSI (c) (F9:49): Executing op:
ActionStart(Name=DisableNetAccess.2D02443E_7002_4C 0B_ABC9_EAB2C064397B,,)
Action 1:56:36: DisableNetAccess.2D02443E_7002_4C0B_ABC9_EAB2C0643 97B.
MSI (c) (F9:49): Executing op:
CustomActionSchedule(Action=DisableNetAccess.2D024 43E_7002_4C0B_ABC9_EAB2C06
4397B,ActionType=1025,Source=BinaryData,Target=Dis ableNetAccess,)
MSI (c) (F9:49): Creating MSIHANDLE (216) of type 790536 for thread -624311
MSI (c) (F9:49): Closing MSIHANDLE (216) of type 790536 for thread -624311
MSI (c) (F9:49): Note: 1: 1723 2:
DisableNetAccess.2D02443E_7002_4C0B_ABC9_EAB2C0643 97B 3: DisableNetAccess 4:
C:\WINDOWS\TEMP\MSI8240.TMP
Error 1723. There is a problem with this Windows Installer package. A DLL
required for this install to complete could not be run. Contact your support
personnel or package vendor. Action
DisableNetAccess.2D02443E_7002_4C0B_ABC9_EAB2C0643 97B, entry:
DisableNetAccess, library: C:\WINDOWS\TEMP\MSI8240.TMP
MSI (c) (F9:49): Product: Microsoft SQL Server Desktop Engine -- Error 1723.
There is a problem with this Windows Installer package. A DLL required for
this install to complete could not be run. Contact your support personnel or
package vendor. Action Di
sableNetAccess.2D02443E_7002_4C0B_ABC9_EAB2C064397 B, entry:
DisableNetAccess, library: C:\WINDOWS\TEMP\MSI8240.TMP
Action ended 2:00:51: InstallFinalize. Return value 3.
Too hard to tell from the log excerpt. You probably have to know what these log entries mean in detail. And frankly, it looks like a Windows Installer problem.
Some suggestions:
1) Let us know what version of MSDE this is, what other instances have been installed. MSDE 2000A is free and available for download from MS.
2) Check the MS SQL Server 2000 books online for info about Win 98. There will be authetication issues with the OS.
3) Please be sure that your OS has all the latest patches installed.
Lou Arnold
Ottawa, Canada
"Lance Johnson" wrote:

> Windows98 machine and when installing MSDE we (our customer) gets an error
> on DisableNetAccess. I have no idea what they should do and I can't find
> anything in google with the word disablenetaccess so I'm hoping somebody out
> there has some info. Below is the relevant info from the log file when
> trying to install.
> MSI (c) (F9:49): Executing op:
> ActionStart(Name=DisableNetAccess.2D02443E_7002_4C 0B_ABC9_EAB2C064397B,,)
> Action 1:56:36: DisableNetAccess.2D02443E_7002_4C0B_ABC9_EAB2C0643 97B.
> MSI (c) (F9:49): Executing op:
> CustomActionSchedule(Action=DisableNetAccess.2D024 43E_7002_4C0B_ABC9_EAB2C06
> 4397B,ActionType=1025,Source=BinaryData,Target=Dis ableNetAccess,)
> MSI (c) (F9:49): Creating MSIHANDLE (216) of type 790536 for thread -624311
> MSI (c) (F9:49): Closing MSIHANDLE (216) of type 790536 for thread -624311
> MSI (c) (F9:49): Note: 1: 1723 2:
> DisableNetAccess.2D02443E_7002_4C0B_ABC9_EAB2C0643 97B 3: DisableNetAccess 4:
> C:\WINDOWS\TEMP\MSI8240.TMP
> Error 1723. There is a problem with this Windows Installer package. A DLL
> required for this install to complete could not be run. Contact your support
> personnel or package vendor. Action
> DisableNetAccess.2D02443E_7002_4C0B_ABC9_EAB2C0643 97B, entry:
> DisableNetAccess, library: C:\WINDOWS\TEMP\MSI8240.TMP
> MSI (c) (F9:49): Product: Microsoft SQL Server Desktop Engine -- Error 1723.
> There is a problem with this Windows Installer package. A DLL required for
> this install to complete could not be run. Contact your support personnel or
> package vendor. Action Di
> sableNetAccess.2D02443E_7002_4C0B_ABC9_EAB2C064397 B, entry:
> DisableNetAccess, library: C:\WINDOWS\TEMP\MSI8240.TMP
> Action ended 2:00:51: InstallFinalize. Return value 3.
>
>
|||This is the latest msde version sp3a I believe. So they are installing the
latest. I'll check to make sure they have all the latest patches for
windows. Any other suggestions are welcome.
Thanks,
Lance Johnson
"Lou Arnold" <Lou_Arnold@.nospam.com> wrote in message
news:3AC49276-818A-446B-BEE4-30B8EF2DD695@.microsoft.com...
> Too hard to tell from the log excerpt. You probably have to know what
these log entries mean in detail. And frankly, it looks like a Windows
Installer problem.
> Some suggestions:
> 1) Let us know what version of MSDE this is, what other instances have
been installed. MSDE 2000A is free and available for download from MS.
> 2) Check the MS SQL Server 2000 books online for info about Win 98. There
will be authetication issues with the OS.[vbcol=seagreen]
> 3) Please be sure that your OS has all the latest patches installed.
> --
> Lou Arnold
> Ottawa, Canada
>
> "Lance Johnson" wrote:
error[vbcol=seagreen]
find[vbcol=seagreen]
out[vbcol=seagreen]
ActionStart(Name=DisableNetAccess.2D02443E_7002_4C 0B_ABC9_EAB2C064397B,,)[vbcol=seagreen]
CustomActionSchedule(Action=DisableNetAccess.2D024 43E_7002_4C0B_ABC9_EAB2C06[vbcol=seagreen]
thread -624311[vbcol=seagreen]
thread -624311[vbcol=seagreen]
DisableNetAccess 4:[vbcol=seagreen]
DLL[vbcol=seagreen]
support[vbcol=seagreen]
1723.[vbcol=seagreen]
for[vbcol=seagreen]
personnel or[vbcol=seagreen]

2012年2月14日星期二

Disable autogrowth of file thru TSQL

Is there a way to programatically disable autogrowth of all database files
residing on a particular drive ? Can someone help ?
Even if I cant do it for all database files in one shot, how can I do them
for individual databases ? Using SQL 2K
Have you tried the ALTER DATABASE...MODIFY FILE command?
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>
|||The basic syntax for disabling autogrowth on a database file is:
ALTER DATABASE <dbname> MODIFY FILE (NAME = <logical file name>, FILEGROWTH
= 0)
You can do that for all database files with the following script:
DECLARE @.dbname SYSNAME
DECLARE @.filename SYSNAME
CREATE TABLE #dbfiles (dbname sysname NOT NULL, filenm nchar(128))
DECLARE dbs CURSOR FAST_FORWARD
FOR
SELECT name FROM master..sysdatabases
WHERE name NOT IN ('master', 'msdb', 'model', 'tempdb', 'distribution')
-- No messing around with system databases
OPEN dbs
WHILE 1 = 1
BEGIN
FETCH NEXT FROM dbs INTO @.dbname
IF @.@.FETCH_STATUS <> 0 BREAK
EXEC ('INSERT INTO #dbfiles(dbname, filenm)
SELECT ''' + @.dbname + ''', name FROM ' + @.dbname + '..sysfiles
WHERE growth > 0
AND filename LIKE ''C:\%''')
END
CLOSE dbs
DEALLOCATE dbs
SELECT * FROM #dbfiles
DECLARE dbfiles CURSOR FAST_FORWARD FOR
SELECT dbname, filenm FROM #dbfiles
OPEN dbfiles
WHILE 1 = 1
BEGIN
FETCH NEXT FROM dbfiles INTO @.dbname, @.filename
IF @.@.FETCH_STATUS <> 0 BREAK
EXEC ('ALTER DATABASE ' + @.dbname + ' MODIFY FILE (NAME = '
+ @.filename + ', FILEGROWTH = 0)')
END
CLOSE dbfiles
DEALLOCATE dbfiles
DROP TABLE #dbfiles
GO
Jacco Schalkwijk
SQL Server MVP
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>
|||Hi
You can use the alter database command on each database. sp_MSForEachDB will
allow you to perform the code for each database, but as this is undocumented
it should not be used in production code, alternatively you can use a cursor
to get the databases from master..sysdatabases. sp_helpfile will give you
where the files are located.
John
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>

Disable autogrowth of file thru TSQL

Is there a way to programatically disable autogrowth of all database files
residing on a particular drive ? Can someone help ?
Even if I cant do it for all database files in one shot, how can I do them
for individual databases ? Using SQL 2KHave you tried the ALTER DATABASE...MODIFY FILE command?
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>|||The basic syntax for disabling autogrowth on a database file is:
ALTER DATABASE <dbname> MODIFY FILE (NAME = <logical file name>, FILEGROWTH
= 0)
You can do that for all database files with the following script:
DECLARE @.dbname SYSNAME
DECLARE @.filename SYSNAME
CREATE TABLE #dbfiles (dbname sysname NOT NULL, filenm nchar(128))
DECLARE dbs CURSOR FAST_FORWARD
FOR
SELECT name FROM master..sysdatabases
WHERE name NOT IN ('master', 'msdb', 'model', 'tempdb', 'distribution')
-- No messing around with system databases
OPEN dbs
WHILE 1 = 1
BEGIN
FETCH NEXT FROM dbs INTO @.dbname
IF @.@.FETCH_STATUS <> 0 BREAK
EXEC ('INSERT INTO #dbfiles(dbname, filenm)
SELECT ''' + @.dbname + ''', name FROM ' + @.dbname + '..sysfiles
WHERE growth > 0
AND filename LIKE ''C:\%''')
END
CLOSE dbs
DEALLOCATE dbs
SELECT * FROM #dbfiles
DECLARE dbfiles CURSOR FAST_FORWARD FOR
SELECT dbname, filenm FROM #dbfiles
OPEN dbfiles
WHILE 1 = 1
BEGIN
FETCH NEXT FROM dbfiles INTO @.dbname, @.filename
IF @.@.FETCH_STATUS <> 0 BREAK
EXEC ('ALTER DATABASE ' + @.dbname + ' MODIFY FILE (NAME = '
+ @.filename + ', FILEGROWTH = 0)')
END
CLOSE dbfiles
DEALLOCATE dbfiles
DROP TABLE #dbfiles
GO
--
Jacco Schalkwijk
SQL Server MVP
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>|||Hi
You can use the alter database command on each database. sp_MSForEachDB will
allow you to perform the code for each database, but as this is undocumented
it should not be used in production code, alternatively you can use a cursor
to get the databases from master..sysdatabases. sp_helpfile will give you
where the files are located.
John
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>

Disable autogrowth of file thru TSQL

Is there a way to programatically disable autogrowth of all database files
residing on a particular drive ? Can someone help ?
Even if I cant do it for all database files in one shot, how can I do them
for individual databases ? Using SQL 2KHave you tried the ALTER DATABASE...MODIFY FILE command?
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>|||The basic syntax for disabling autogrowth on a database file is:
ALTER DATABASE <dbname> MODIFY FILE (NAME = <logical file name>, FILEGROWTH
= 0)
You can do that for all database files with the following script:
DECLARE @.dbname SYSNAME
DECLARE @.filename SYSNAME
CREATE TABLE #dbfiles (dbname sysname NOT NULL, filenm nchar(128))
DECLARE dbs CURSOR FAST_FORWARD
FOR
SELECT name FROM master..sysdatabases
WHERE name NOT IN ('master', 'msdb', 'model', 'tempdb', 'distribution')
-- No messing around with system databases
OPEN dbs
WHILE 1 = 1
BEGIN
FETCH NEXT FROM dbs INTO @.dbname
IF @.@.FETCH_STATUS <> 0 BREAK
EXEC ('INSERT INTO #dbfiles(dbname, filenm)
SELECT ''' + @.dbname + ''', name FROM ' + @.dbname + '..sysfiles
WHERE growth > 0
AND filename LIKE ''C:\%''')
END
CLOSE dbs
DEALLOCATE dbs
SELECT * FROM #dbfiles
DECLARE dbfiles CURSOR FAST_FORWARD FOR
SELECT dbname, filenm FROM #dbfiles
OPEN dbfiles
WHILE 1 = 1
BEGIN
FETCH NEXT FROM dbfiles INTO @.dbname, @.filename
IF @.@.FETCH_STATUS <> 0 BREAK
EXEC ('ALTER DATABASE ' + @.dbname + ' MODIFY FILE (NAME = '
+ @.filename + ', FILEGROWTH = 0)')
END
CLOSE dbfiles
DEALLOCATE dbfiles
DROP TABLE #dbfiles
GO
Jacco Schalkwijk
SQL Server MVP
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>|||Hi
You can use the alter database command on each database. sp_MSForEachDB will
allow you to perform the code for each database, but as this is undocumented
it should not be used in production code, alternatively you can use a cursor
to get the databases from master..sysdatabases. sp_helpfile will give you
where the files are located.
John
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OP7kEkUTFHA.612@.TK2MSFTNGP12.phx.gbl...
> Is there a way to programatically disable autogrowth of all database files
> residing on a particular drive ? Can someone help ?
> Even if I cant do it for all database files in one shot, how can I do them
> for individual databases ? Using SQL 2K
>