Showing posts with label persistent. Show all posts
Showing posts with label persistent. Show all posts

Wednesday, March 28, 2012

persistent SQLBrowser error eventID 3

I have what looks like a completed install of SQL Server Express Edition, accomplished via unattended setup as part of a custom application (on a machine hereafter dubbed Machine "A").

So far, though, I can't access this instance from a remote SQL Server Management Studio because SSMSE can't see the installed database engine.

I've verified that:

The SQL Server Express installation on Machine A has remote connections enabled.

The SQLBrowser on Machine A is enabled and running.

Machine A's Windows Firewall is disabled.

Using a test tool, I can see that UDP messages sent to SQLBrowser (on port 1434), arrive (i.e. it complains about their format in the System Log).

It seems that Machine A's SQLBrowser isn't responding to requests, but there's no obvious reason why.

There's one clue in Machine A's event log:

Whenever SQLBrowser is started or restarted, there's a warning in the App Log:

"The configuration of the AdminConnection\TCP protocol in the SQL instance SQLEXPRESS is not valid." (eventid 3).

Any help will be much appreciated.

Thanks in advance
Josh

Some more diverse testing reveals that the problem seems to occur only when SSMSEE is running on Windows 2000.

The source of the problem appears to be that W2K is not picking up the correct instance name (in other words, it puts MYSERVER in the list of engines, but not MYSERVER\SQLEXPRESS). If I key in MYSERVER\SQLEXPRESS by hand, things work as expected.

Incidentally, I noticed that when running under XP, the Network Server list shows which version of the SQL Engine is running on each server, but under Windows 2000, it does this only for very few of the servers.

Is this a shade of a known problem?

Josh

Persistent mirroring witness disconnected probem on mirror

Hi,
I'm running a syncornized mirroring setup using a witness on our LAN.
Since we don't use a domain controller, we use certificates for outbound and
inbound mirroring connections.
We're using sql server 2005 SP1 standard edititon on all machines.
The principal and mirror have only the partner role
The witness has only the witness role
After exeucting 'alter database set witness' on server1, the mirror monitor
shows that server1, the pricnipal, is connected to the witness, but server2,
the mirror, is disconnected from the witness.
When performing a manual failover (alter databsase set partner failover),
server2, now the principal, is still disconnected from the witness.
I've eliminated the possibility that server2 and the witness have a
connection problem, by dropping the witness from server1 when server1 was the
principal, and adding it to server2, when server2 was the principal. Then,
server1 is the one with the disconnected problem.
When executing the set witness command on a mirror, I get an error that it
can only be done on the principal machine.
Any ideas?
Thanks,
Ronen
The error message is exactly correct. You run an alter database set partner
on both the principal and the mirror. You only run the alter database set
witness on the principal. That command option is never run against the
mirror. It looks like you have either a certificate issue or you have a
connectivity problem. If the principal and mirror are server1 and server2,
what is the name of the witness?
Mike Hotek
MHS Enterprises, Inc
http://www.mssqlserver.com
"Ronen" <Ronen@.discussions.microsoft.com> wrote in message
news:C3C6E7E5-AA18-4A24-BC34-3C378D05A41D@.microsoft.com...
> Hi,
> I'm running a syncornized mirroring setup using a witness on our LAN.
> Since we don't use a domain controller, we use certificates for outbound
> and
> inbound mirroring connections.
> We're using sql server 2005 SP1 standard edititon on all machines.
> The principal and mirror have only the partner role
> The witness has only the witness role
> After exeucting 'alter database set witness' on server1, the mirror
> monitor
> shows that server1, the pricnipal, is connected to the witness, but
> server2,
> the mirror, is disconnected from the witness.
> When performing a manual failover (alter databsase set partner failover),
> server2, now the principal, is still disconnected from the witness.
> I've eliminated the possibility that server2 and the witness have a
> connection problem, by dropping the witness from server1 when server1 was
> the
> principal, and adding it to server2, when server2 was the principal. Then,
> server1 is the one with the disconnected problem.
> When executing the set witness command on a mirror, I get an error that it
> can only be done on the principal machine.
> Any ideas?
> Thanks,
> Ronen
>
sql

Persistent lookups

I read on the SQL Server 2008 Overview paper that there is a new "SSIS persistent lookup" feature.

Performing lookups is a common operation, especially in data warehousing, where fact records must use lookups to transform business keys to their corresponding surrogates. SQL Server Integration Services (SSIS) will increase the performance of lookups so that it scales to meet the largest tables.

I'd like to know how this is different from the existing 2005 lookup.

Marco Russo

http://www.sqlbi.eu

http://sqlblog.com/blogs/marco_russo

{disclaimer about unreleased software and unconfirmed features that can and will change before the release}

In SQL 2005, when the reference table is large and you are using fully cached mode, sometimes it takes longer to get the data out of reference table (OLEDB data source) and hash it for lookup, than to do the actual lookup on the input data.

In SQL 2008 we plan to allow persisting reference table and hashes, so that the reference table can be loaded faster from a local disk. You would not have to touch database that contains that reference table every time you use the lookup.

{disclaimer about unreleased software and unconfirmed features that can and will change before the release}

|||

Thank you - I hope to see early a new CTP to try this feature.

Marco

persistent full text catalog

Hi
I've a database in development environment that uses a full text catalog
created on the directory d:\abc
When i migrate my database to production, on another server, i did the
complete restore from my backup done in development
all tables and so passed ok but my catalogs remains with the old path d:\abc
that doesn't exists on the new server (d: is cdrom)
how can i change it?!?1
i tried to use sp_fulltext_catalog 'cat', 'rebuild', 'new_path' and it
reported error saying thet the database is not yet fulltext enabled
i then tried to do so using sp_fulltext_database 'enable' and the error
returned was something like 'can't enable catalgos because path d:\abc does
not exists'
when i try to delete the catalog it again reports the fact that the database
is not fulltext enabled...
it seems that this is an infinite loop...
deleting the row from sysfulltextcatalogs does not do it because it removes
it but does not let me create another on on the same tables that the previous
was
using sp_fulltext_table and sp_fulltext_columns the error is te same...
how can i go arround this?!?!
best regards
Jorge Ribeiro
Jorge,
This is a bug related to moving / restoring FT-enabled databases to another
server where the drive letter for the FT Catalogs is different than the
orgianal server. You can work around this this "Catch-22" situation with the
following code (Note: Sysadmin level permission is required):
-- Enable System Table UPDATEs
sp_configure allow,1
go
reconfigure with override
go
use <your_user_database_name>
go
-- Record FT Catalog info. (Note: path = NULL)
select * from sysfulltextcatalogs
go
UPDATE sysfulltextcatalogs set path = '<new_drive_letter:\<new_directory>'
WHERE ftcatid = <ftcatid_of_affected_catalog>
go
-- Record new FT Catalog info.
select * from sysfulltextcatalogs
go
use master
go
-- Disenable System Table UPDATEs
sp_configure allow,0
go
reconfigure with override
go
Regards,
John
"Jorge Ribeiro" <JorgeRibeiro@.discussions.microsoft.com> wrote in message
news:BDA37D16-A43A-4F51-9D9A-57F3CF7AE5B3@.microsoft.com...
> Hi
> I've a database in development environment that uses a full text catalog
> created on the directory d:\abc
> When i migrate my database to production, on another server, i did the
> complete restore from my backup done in development
> all tables and so passed ok but my catalogs remains with the old path
d:\abc
> that doesn't exists on the new server (d: is cdrom)
> how can i change it?!?1
> i tried to use sp_fulltext_catalog 'cat', 'rebuild', 'new_path' and it
> reported error saying thet the database is not yet fulltext enabled
> i then tried to do so using sp_fulltext_database 'enable' and the error
> returned was something like 'can't enable catalgos because path d:\abc
does
> not exists'
> when i try to delete the catalog it again reports the fact that the
database
> is not fulltext enabled...
> it seems that this is an infinite loop...
> deleting the row from sysfulltextcatalogs does not do it because it
removes
> it but does not let me create another on on the same tables that the
previous
> was
> using sp_fulltext_table and sp_fulltext_columns the error is te same...
>
> how can i go arround this?!?!
> best regards
> Jorge Ribeiro

Persistent Database Corruption

I am having an issue with persistent database corruption when copying
databases between instances. We have a production system with an 8GB (or
so) database that I copy over to our test systems on a regular basis.
A DBCC CHECKDB on this production database reports no issues. After
restoring the database (I do a backup and use the backup file to effect
the restore on a remote system via SQL Scripts) I have consistent
reports of corruption on the database when it is restored on the test
system.
A RESTORE VERIFYONLY on the backup file before restore only says "The
backup set is valid."
The amount of corruption varies; I have seen anywhere from 6 to 60
consistency errors.
I know this may be caused by underlying network or disk issues, but I'm
not sure how to go about confirming this when I don't see any other
related errors in the SQL or Windows event logs on the machine in question.
Stats:
SQL Server 2000 Enterprise SP3 (on an Active-Active cluster)
Windows Server 2003 Enterprise
4GB RAM
iSCSI SAN for all cluster-related disks using MS iSCSI drivers
Thanks,
JoshHmm. iSCSI drives. I have seen way too many problems with those. The MS
drivers may be just fine, but the iSCSI devices often cannot keep up with
the I/O load a SQL server can dish out. If he is paying attention, maybe
Dr. Tom Moreau will describe the hell he went through trying to use iSCSI
devices for a client.
--
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"Joshua Andrews" <jrandrew@.nospam.hotmail.com> wrote in message
news:uNmE2Pu0GHA.4796@.TK2MSFTNGP06.phx.gbl...
>I am having an issue with persistent database corruption when copying
>databases between instances. We have a production system with an 8GB (or
>so) database that I copy over to our test systems on a regular basis.
> A DBCC CHECKDB on this production database reports no issues. After
> restoring the database (I do a backup and use the backup file to effect
> the restore on a remote system via SQL Scripts) I have consistent reports
> of corruption on the database when it is restored on the test system.
> A RESTORE VERIFYONLY on the backup file before restore only says "The
> backup set is valid."
> The amount of corruption varies; I have seen anywhere from 6 to 60
> consistency errors.
> I know this may be caused by underlying network or disk issues, but I'm
> not sure how to go about confirming this when I don't see any other
> related errors in the SQL or Windows event logs on the machine in
> question.
> Stats:
> SQL Server 2000 Enterprise SP3 (on an Active-Active cluster)
> Windows Server 2003 Enterprise
> 4GB RAM
> iSCSI SAN for all cluster-related disks using MS iSCSI drivers
> Thanks,
> Josh|||Can you post few consistency error you facing?
--
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and time
asking back if its 2000 or 2005]
"Joshua Andrews" wrote:
> I am having an issue with persistent database corruption when copying
> databases between instances. We have a production system with an 8GB (or
> so) database that I copy over to our test systems on a regular basis.
> A DBCC CHECKDB on this production database reports no issues. After
> restoring the database (I do a backup and use the backup file to effect
> the restore on a remote system via SQL Scripts) I have consistent
> reports of corruption on the database when it is restored on the test
> system.
> A RESTORE VERIFYONLY on the backup file before restore only says "The
> backup set is valid."
> The amount of corruption varies; I have seen anywhere from 6 to 60
> consistency errors.
> I know this may be caused by underlying network or disk issues, but I'm
> not sure how to go about confirming this when I don't see any other
> related errors in the SQL or Windows event logs on the machine in question.
> Stats:
> SQL Server 2000 Enterprise SP3 (on an Active-Active cluster)
> Windows Server 2003 Enterprise
> 4GB RAM
> iSCSI SAN for all cluster-related disks using MS iSCSI drivers
> Thanks,
> Josh
>|||Sreejith G wrote:
> Can you post few consistency error you facing?
Sure.
DBCC results for 'Table1'.
There are 3211496 rows in 94093 pages for object 'Table1'.
CHECKDB found 0 allocation errors and 2 consistency errors in table
'Table1' (object ID 1793857903).
*********
Bunch of clean tables
*********
DBCC results for 'Table2'.
There are 89870 rows in 2124 pages for object 'Table2'.
CHECKDB found 0 allocation errors and 2 consistency errors in table
'CMN_PersonsSearchInfo' (object ID 1629248859).
*********
Bunch of clean tables
*********
DBCC results for 'Table3'.
There are 196205 rows in 3616 pages for object 'Table3'.
CHECKDB found 0 allocation errors and 6 consistency errors in table
'Table3' (object ID 1565248631).
*********
Bunch of clean tables
*********
CHECKDB found 0 allocation errors and 64 consistency errors in database
'DataDB'.
repair_allow_data_loss is the minimum repair level for the errors found
by DBCC CHECKDB (DataDB ).
DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
Of course, there are more, but the above is just a sample.
Thanks!
Josh

Persistent Database Corruption

I am having an issue with persistent database corruption when copying
databases between instances. We have a production system with an 8GB (or
so) database that I copy over to our test systems on a regular basis.
A DBCC CHECKDB on this production database reports no issues. After
restoring the database (I do a backup and use the backup file to effect
the restore on a remote system via SQL Scripts) I have consistent
reports of corruption on the database when it is restored on the test
system.
A RESTORE VERIFYONLY on the backup file before restore only says "The
backup set is valid."
The amount of corruption varies; I have seen anywhere from 6 to 60
consistency errors.
I know this may be caused by underlying network or disk issues, but I'm
not sure how to go about confirming this when I don't see any other
related errors in the SQL or Windows event logs on the machine in question.
Stats:
SQL Server 2000 Enterprise SP3 (on an Active-Active cluster)
Windows Server 2003 Enterprise
4GB RAM
iSCSI SAN for all cluster-related disks using MS iSCSI drivers
Thanks,
JoshHmm. iSCSI drives. I have seen way too many problems with those. The MS
drivers may be just fine, but the iSCSI devices often cannot keep up with
the I/O load a SQL server can dish out. If he is paying attention, maybe
Dr. Tom Moreau will describe the hell he went through trying to use iSCSI
devices for a client.
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"Joshua Andrews" <jrandrew@.nospam.hotmail.com> wrote in message
news:uNmE2Pu0GHA.4796@.TK2MSFTNGP06.phx.gbl...
>I am having an issue with persistent database corruption when copying
>databases between instances. We have a production system with an 8GB (or
>so) database that I copy over to our test systems on a regular basis.
> A DBCC CHECKDB on this production database reports no issues. After
> restoring the database (I do a backup and use the backup file to effect
> the restore on a remote system via SQL Scripts) I have consistent reports
> of corruption on the database when it is restored on the test system.
> A RESTORE VERIFYONLY on the backup file before restore only says "The
> backup set is valid."
> The amount of corruption varies; I have seen anywhere from 6 to 60
> consistency errors.
> I know this may be caused by underlying network or disk issues, but I'm
> not sure how to go about confirming this when I don't see any other
> related errors in the SQL or Windows event logs on the machine in
> question.
> Stats:
> SQL Server 2000 Enterprise SP3 (on an Active-Active cluster)
> Windows Server 2003 Enterprise
> 4GB RAM
> iSCSI SAN for all cluster-related disks using MS iSCSI drivers
> Thanks,
> Josh|||Can you post few consistency error you facing?
--
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and
time
asking back if its 2000 or 2005]
"Joshua Andrews" wrote:

> I am having an issue with persistent database corruption when copying
> databases between instances. We have a production system with an 8GB (or
> so) database that I copy over to our test systems on a regular basis.
> A DBCC CHECKDB on this production database reports no issues. After
> restoring the database (I do a backup and use the backup file to effect
> the restore on a remote system via SQL Scripts) I have consistent
> reports of corruption on the database when it is restored on the test
> system.
> A RESTORE VERIFYONLY on the backup file before restore only says "The
> backup set is valid."
> The amount of corruption varies; I have seen anywhere from 6 to 60
> consistency errors.
> I know this may be caused by underlying network or disk issues, but I'm
> not sure how to go about confirming this when I don't see any other
> related errors in the SQL or Windows event logs on the machine in question
.
> Stats:
> SQL Server 2000 Enterprise SP3 (on an Active-Active cluster)
> Windows Server 2003 Enterprise
> 4GB RAM
> iSCSI SAN for all cluster-related disks using MS iSCSI drivers
> Thanks,
> Josh
>|||Sreejith G wrote:
> Can you post few consistency error you facing?
Sure.
DBCC results for 'Table1'.
There are 3211496 rows in 94093 pages for object 'Table1'.
CHECKDB found 0 allocation errors and 2 consistency errors in table
'Table1' (object ID 1793857903).
*********
Bunch of clean tables
*********
DBCC results for 'Table2'.
There are 89870 rows in 2124 pages for object 'Table2'.
CHECKDB found 0 allocation errors and 2 consistency errors in table
'CMN_PersonsSearchInfo' (object ID 1629248859).
*********
Bunch of clean tables
*********
DBCC results for 'Table3'.
There are 196205 rows in 3616 pages for object 'Table3'.
CHECKDB found 0 allocation errors and 6 consistency errors in table
'Table3' (object ID 1565248631).
*********
Bunch of clean tables
*********
CHECKDB found 0 allocation errors and 64 consistency errors in database
'DataDB'.
repair_allow_data_loss is the minimum repair level for the errors found
by DBCC CHECKDB (DataDB ).
DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
Of course, there are more, but the above is just a sample.
Thanks!
Josh

Persistent communication session inside sqlclr proc?

I suspect this is very poor design but I've been asked to research this: can I maintain a persistent communication session inside an sqlclr proc? (tcp/binary packets)

The process has to maintain very high throughput - setting up and tearing down a connection on each transaction is cost prohibitive. For TCO and deployment reasons it is preferable not to have a separate windows service etc that accepts requests from inside the clr proc. Is there the luxury of an alternative integrated into the database?

DONT DO THIS, stored procedures are not windows services. And i believe SQL Server monitors for long running CLR threads and will auto-suspend them. There is some bits and pieces about this in BOL2005.|||Thanks Derek - I have all the ammunition I need know to make an alternate design proposal. I think we've all seen in the past what happens when database servers are used for anything else than a persistence sink and transaction/report processor. Hardware is just too cheap to misuse platforms like this.|||

if you are satisfied please mark an answer.

Thanks,

"D"

sql

Persistent BI Studio Crashes

I am wondering if anyone has experienced the same persistent BI Studio crashes that I have. I can get the BI Studio to crash by simply opening a report and toggling back and forth on the Data/Layout/Preview tabs.

Here are the steps:

Launch BI Studio
Open Solution
Open Report in designer (layout tab defaulted)
Click Preview tab, then View Report button
Toggle tab to Layout, then Data, then back to Layout, then Preview

Boom...Visual Studio throws an exception and I lose all changes.

It happened about 20 times yesterday.

I have a solution with one Analysis Services project and one Reporting Services project. Should I keep my solutions to one project?

Am I on a stable version of the software?

Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: IDE Standard

SQL Server Analysis Services
Microsoft SQL Server Analysis Services Designer
Version 9.00.1399.00

SQL Server Integration Services
Microsoft SQL Server Integration Services Designer
Version 9.00.1399.00

SQL Server Reporting Services
Microsoft SQL Server Reporting Services Designers
Version 9.00.1399.00

Any clues would be appreciated.

Thanks!

I am not seeing that, but did you create the report in the report wizard, or by hand?

I am having similar problems when I use the wizard to create a report.

BobP

|||

I have been getting this. I now have a erport that is just 1 table, based on a dataset which is getting data from the sysdtslog90 table.

When ever I go to preview BI studio crashes.

Faulting application devenv.exe, version 8.0.50727.42, stamp 4333e699, faulting module kernel32.dll, version 5.1.2600.2180, stamp 411096b4, debug? 0, fault address 0x0001eb33.

|||Same problem here. Has anyone found anything further on this?

Persistent BI Studio Crashes

I am wondering if anyone has experienced the same persistent BI Studio crashes that I have. I can get the BI Studio to crash by simply opening a report and toggling back and forth on the Data/Layout/Preview tabs.

Here are the steps:

Launch BI Studio
Open Solution
Open Report in designer (layout tab defaulted)
Click Preview tab, then View Report button
Toggle tab to Layout, then Data, then back to Layout, then Preview

Boom...Visual Studio throws an exception and I lose all changes.

It happened about 20 times yesterday.

I have a solution with one Analysis Services project and one Reporting Services project. Should I keep my solutions to one project?

Am I on a stable version of the software?

Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: IDE Standard

SQL Server Analysis Services
Microsoft SQL Server Analysis Services Designer
Version 9.00.1399.00

SQL Server Integration Services
Microsoft SQL Server Integration Services Designer
Version 9.00.1399.00

SQL Server Reporting Services
Microsoft SQL Server Reporting Services Designers
Version 9.00.1399.00

Any clues would be appreciated.

Thanks!

I am not seeing that, but did you create the report in the report wizard, or by hand?

I am having similar problems when I use the wizard to create a report.

BobP

|||

I have been getting this. I now have a erport that is just 1 table, based on a dataset which is getting data from the sysdtslog90 table.

When ever I go to preview BI studio crashes.

Faulting application devenv.exe, version 8.0.50727.42, stamp 4333e699, faulting module kernel32.dll, version 5.1.2600.2180, stamp 411096b4, debug? 0, fault address 0x0001eb33.

|||Same problem here. Has anyone found anything further on this?

Persistent autoincrementing value, not attached to row insertion?

I need to get a unique value to use for a record *before* the record is added to a table. It doesn't have to be contiguous with existing records, but it must always be unique, has to be persistent over multiple instantiations of an ASP.NET application, and has to work in that sort of a multi-session environment (where other sessions could need additional unique values before the first session gets around to actually adding a record to the table).

I considered generating and using unique CLSIDs for this, but the resulting value also needs to become part of the filename of some files that are being saved to the disk (and those names also saved in the table), and including text CLSIDs along with other filename data would make for some unpleasantly long and difficult to work with filenames.

I also don't think there's a practical way for me to use a trigger associated with an identity column for this, because I need to save files to disk using the unique value before I even know if the record will in fact end up being added to the table, and what's more, the numbers and names of those files will vary in ways that might be difficult to handle in a stored procedure.

What I'm thinking I will have to do is create a separate database table called something like "UniqueIDGen". This table would have a single record in it with a single integer value, initialized to a value of 1. Then, each time an ID is needed, this one record would be locked, read and incremented by 1. The only reason for doing it this way instead of with an application variable, as I see it, is that the values need to be unique and continue incrementing in perpetuity, no matter how many times the ASP.NET application is recycled or the server is rebooted.

But I still have to wonder if there might be a more efficient method provided by SQL Server for this type of unique value generation ... something that is equally as persistent without requiring an entire table with only a single record to be allocated to such a basic task. Does anyone know of a more elegant solution for this?do a hash of the current date.time.milliseconds, or a unix timestamp in the backend of the asp.net, unless you plan on data being entered in the same second.|||Is there no better option based upon SQL Server or some other persistent technology, other than the workable but awkward solution I mentioned? For some reason I thought there might be a non-table-based identity value, or something like that, specifically for situations like this. Perhaps that is something I'm remembering from some other RDBMS software I dealt with in the past, and not SQL Server?|||Hi,

You could do this, it is a bit like Oracle's NextVal:

CREATE TABLE dbo.Sequences
(
ID int NOT NULL
)

INSERT INTO Sequences (ID) VALUES (0)

CREATE PROCEDURE dbo.NextValue
@.ID int output
AS
UPDATE Sequences SET ID = ID + 1, @.ID = ID + 1
RETURN

And call the stored proc to get the ID.


private void Button1_Click(object sender, System.EventArgs e)
{
string connectionString = @."Server=wpeude-masonix2;Database=TestDatabase;User ID=sa;Password=sa;Trusted_Connection=False";

SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "dbo.NextValue";
command.CommandType = CommandType.StoredProcedure;

SqlParameter param = new SqlParameter("@.ID", SqlDbType.Int, 4);
param.Direction = ParameterDirection.Output;
command.Parameters.Add(param);

connection.Open();
command.ExecuteNonQuery();
int pk = (int)param.Value;
connection.Close();
lblNextValue.Text = pk.ToString();
}

The ID would be unique in the Database. You could change the sproc to use NEWID() and have a varchar column instead, if you wanted to use a GUID.

A.|||asmason,

Your example is precisely the solution I proposed in my original post (unless I did an insufficient job of describing what I was thinking of). If there's no method available that's superior to creating a table for this purpose, then I'll go ahead and do it that way.

Thanks for taking the time to write it up.|||Couldn't you take and make a stored procedure that makes it for you? Basically when you go to insert a value you do a :


select @.IDVariable = Max(IDField) from Table

Then when you insert:

 Insert into Table (IDField) Values (@.IDVariable)

I have done something very similar to this in several projects and it remains unique and it is available when you create it.|||Regarding the suggestion of:

select @.IDVariable = Max(IDField) from Table

... and then ...
Insert into Table (IDField) Values (@.IDVariable)

I don't think I should do that. In my case, fair amount of time (seconds or even minutes) can potentially elapse between the time I need the unique ID (the first line) and the actual INSERT (the second line). What happens when, when session #1 is sitting at some point in between those two statements, and session #2 comes along and performs the first statement to get an ID for itself? It will get the same one that the first session got ... and then. if both sessions end up inserting a new row using the provided ID ... *biff*, collisions.

In fact, generally it seems like this wouldn't be wholly safe in any multi-threaded environment (even a delay of milliseconds could theoretically lead to a collision, though it might be much less likely than in my current project). Maybe it would be okay if both statements were encased within a single transaction, but that doesn't allow the ID value to be used for things outside of the database, which is a requirement of what I'm working on.

Also, I can only assume that the performance of the MAX function degrades as the number of rows in the table increases, so that may be a bit of a negative as well, at least compared to the standalone "ID table" method.

For what it is worth, I've already gone ahead and implemented a table for this task, very similar to the code that asmason included above, and it works very nicely. I did add one thing: a "counter_name" field, so that the same table could be used to maintain additional unique counters or values if I run across similiar needs again in the future. Thus, the statement in my stored procedure looks like this:

UPDATE AppCounters SET id = id + 1, @.RETURNID = id + 1 WHERE counter_name = @.ctrname