Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Tuesday, March 27, 2012

Consecutive numbering WITHOUT Identity

Hi,

I'mtrying to insert records from one table into another table. Thedestination table has a ROWID field which cannot be an identity key,but needs to 'act like' an identity key and have its value populatedwith (Max(ROWID) + 1) for each row added to the table.

To mythinking, simply using (Max(ROWID) + 1) in my SELECT statement will notwork as it will only be evaluated once so if I am adding 1000 recordsand Max(ROWID) is 1234, all 1000 entries will end up having a ROWID of1235.

Is there a way to accomplish this?

Thanks

Hi,

you can increment the row id locally in your program after doing an update in a loop:
rowID = <select max rowid blablabla>
while <there are still rows to add>
Command.executenonquery() - using rowID
rowID +=1
Loop

you can also use a trigger in the database to update the rowid column after insert

|||

Yes.

You can readMax(ROWID) from database intoApplication("id") at the start of web application,e.g. 1234 to avoid frequent access to database.

After insert just add id by 1.

Hope it helps.

Tuesday, February 14, 2012

Connection question about using impersonate in webpage

Hi,
I create a webservice and impersonate a specific user only when you run a
connection to sql server to insert the data.
My connection string is as follows:
Integrated Security=SSPI;Persist Security Info=false;Initial
Catalog=cmcMail;Data Source=MASDD1;Network Library=dbmssocn;Packet Size=1024;
I got the error during debugging which is "Error: 18456, Severity: 14,
State: 11" . It means that "Valid login but server access failure"
After running some testings, I have a few questions about the inpersonate
issue:
1. If I user anohter domain user, who has access right to server and
database even to execute the store procedure as same as the specific user.
The data is inserted without problem. Why one can work and another cann't?
2. I tried to user the user is not my database user but can access another
database on the same SQL server.
It didn't raise error, and the data is insert on the table. Why this user
without premission can execute the store procedure.
Thanks
"BMW" wrote:

> Hi,
> I create a webservice and impersonate a specific user only when you run a
> connection to sql server to insert the data.
> My connection string is as follows:
> Integrated Security=SSPI;Persist Security Info=false;Initial
> Catalog=Mail;Data Source=MAS;Network Library=dbmssocn;Packet Size=1024;
> I got the error during debugging which is "Error: 18456, Severity: 14,
> State: 11" . It means that "Valid login but server access failure"
>
> After running some testings, I have a few questions about the inpersonate
> issue:
> 1. If I user anohter domain user, who has access right to server and
> database even to execute the store procedure as same as the specific user.
> The data is inserted without problem. Why one can work and another cann't?
> 2. I tried to user the user is not my database user but can access another
> database on the same SQL server.
> It didn't raise error, and the data is insert on the table. Why this user
> without premission can execute the store procedure.
> Thanks
>

Connection question about using impersonate in webpage

Hi,
I create a webservice and impersonate a specific user only when you run a
connection to sql server to insert the data.
My connection string is as follows:
Integrated Security=SSPI;Persist Security Info=false;Initial
Catalog=cmcMail;Data Source=MASDD1;Network Library=dbmssocn;Packet Size=1024
;
I got the error during debugging which is "Error: 18456, Severity: 14,
State: 11" . It means that "Valid login but server access failure"
After running some testings, I have a few questions about the inpersonate
issue:
1. If I user anohter domain user, who has access right to server and
database even to execute the store procedure as same as the specific user.
The data is inserted without problem. Why one can work and another cann't?
2. I tried to user the user is not my database user but can access another
database on the same SQL server.
It didn't raise error, and the data is insert on the table. Why this user
without premission can execute the store procedure.
Thanks"BMW" wrote:

> Hi,
> I create a webservice and impersonate a specific user only when you run a
> connection to sql server to insert the data.
> My connection string is as follows:
> Integrated Security=SSPI;Persist Security Info=false;Initial
> Catalog=Mail;Data Source=MAS;Network Library=dbmssocn;Packet Size=1024;
> I got the error during debugging which is "Error: 18456, Severity: 14,
> State: 11" . It means that "Valid login but server access failure"
>
> After running some testings, I have a few questions about the inpersonate
> issue:
> 1. If I user anohter domain user, who has access right to server and
> database even to execute the store procedure as same as the specific user.
> The data is inserted without problem. Why one can work and another cann't?
> 2. I tried to user the user is not my database user but can access another
> database on the same SQL server.
> It didn't raise error, and the data is insert on the table. Why this user
> without premission can execute the store procedure.
> Thanks
>