473,811 Members | 3,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Identity Insert

17 New Member
Dear All,

May I ask you a question.

I have got bottle neck in my application.

My vb.net program read Product info from one database and insert to another database.

I wanna to be same ProductID for all databases.

So I used Identity Insert statement in my code and it run properly with sa (system admin role) but it cannot work with other user who is not in system admin role.

Please give me suggestion for this issue.

Thanks in advance.

Here is my code for it.

Expand|Select|Wrap|Line Numbers
  1. Dim objCmd As SqlCommand
  2. Dim objDataAdapter As New SqlDataAdapter
  3. Dim objReader As SqlDataReader
  4. Dim strSQL As String
  5. Dim con As SqlClient.SqlConnection
  6. Dim adapter As SqlClient.SqlDataAdapter
  7. Dim OtherConnection As String
  8.  
  9. OtherConnection = "Data Source=. ;Initial Catalog=MainSaleData;user id=mike;password=mike227;Connect Timeout=360"
  10.  
  11.  
  12. strSQL = "SET IDENTITY_INSERT [Products]ON INSERT INTO Products (ProductID, [Product Code], ProductName   VALUES  ( '" & ProductID & "', '" & pcode & "', '" & ProductName & " ) " & "   SET IDENTITY_INSERT [Products]OFF "
  13.  
  14. con = New SqlClient.SqlConnection(str)
  15. con.ConnectionString = OtherConnection
  16. con.Open()
  17. objCmd = New SqlCommand(strSQL, con)
  18. objDataAdapter.InsertCommand = objCmd
  19. objReader = objCmd.ExecuteReader
  20.  

Mike
Jun 16 '11 #1
2 3903
Joseph Martell
198 Recognized Expert New Member
This sounds like you have a permissions problem with the user you are using to run the query. I have seen some companies in the past create an "applicatio n user id" which is just a user account that is created for, and used by, a specific application. This application user id is then given the required permissions for the target database, file access, etc. This avoids needing to elevate a normal user to an administrator role, which most SQL Admins and network admins do not like to do.

The other option is to talk to your SQL Admin (or do it yourself, if you have that privilege) to change the permissions of your table so it does not take an administrator to use Identity_Insert .
Jun 16 '11 #2
mikewin86
17 New Member
Dear Joseph,


Thanks for your suggestion.

I have already talked to SQL Admin for it but they do not agree and do not want to modify back end.

So I have got headache to solve it from my program.


Mike
Jun 17 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2291
by: (Pete Cresswell) | last post by:
This doesn't work because the first INSERT is creating multiple records for multiple projects. @@IDENTITY, then, contains the Identity column value for the last tblWeekReportedLine record inserted. Consequently, all the hours records are then associated with that last value. The source work table, #EstimateLines, is a pivoted representation with a Begin/End date and some Hours for each of six periods - a line per project that gets...
2
4668
by: Edward | last post by:
SQL 7.0 I have a form in ASP.NET and I want to write the values to the SQL Server tables. The tables are Customer and Address tables. There will be an insert into the Customer table, and I need to use the Identity of this inserted record for the Foreign Key in the Address table insert.
6
2439
by: Maria L | last post by:
I have a client who needs to copy an existing sale. The problem is the Sale is made up of three tables: Sale, SaleEquipment, SaleParts. Each sale can have multiple pieces of equipment with corresponding parts, or parts without equipment. My problem in copying is when I go to copy the parts, how do I get the NEW sale equipment ids updated correctly on their corresponding parts? I can provide more information if necessary. Thank you!!
5
9863
by: grzes | last post by:
MS SQL Server 2000. My case is: I have the table T with primary key calling __recid int without identity property. This table includes a lot of records (about 1000000). I need to convert __recid's data type to IDENTITY. As you know sql sentence: "alter table T alter column __recid int IDENTITY not null" does not work with not-empty tables. I use the SQL Enterprise Manager which can convert the field __recid into identity but I need...
3
2096
by: isaacrajan | last post by:
Hello, How do I get SQL server 2000 to continue the sequence of identity column values after I perform an insert into the table with the set identity_insert <table name> on statement? Eg if I insert values into the identity column with values 1-999, how do I get the next number to be 1000? Can the identity seed value be changed if there are records in the table? Can the identity seed value be re-set to start again from 1? Thanks Isaac
8
4338
by: shenanwei | last post by:
I have 2 same windows machine, same instance configure and Database , all run DB2 UDB V8.1.5 Test 1 : create table OUT_1 (LINE VARCHAR(350), LINENUMBER INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1, NO CACHE)); insert into out_1 (line) values ('C000000002XYTNF102020201855000000075000519600040547000003256510 0000000000000000000000000SIM CAR ADJ JOHN, SMITHJA CPRM SIM CARMBCORL XYTNF1020282726
0
3688
by: shubhangi | last post by:
Hi, I have created a update trigger on a table which has auto incremental field. trigger contains "set identity_insert on" statement. I am facing problem that only logins who have db_owner rights can update but others can't why other logins having db read & write rights are unable to fire update statements through query analyser.
1
2528
by: ddice | last post by:
I need to update and then read a sequence number, but I think its failing when there are many users updating at the same time. Here's what I'm doing update datatable set nextnr = nextnr+1 where somecondition select nextnr from datatable where somecondition I don't think I always get the correct sequence number. There must be a better way to do this. Thanks
2
2098
by: Marie-Christine Bechara | last post by:
I have a table with id an identity column. Can I forbid the identity column of taking the same values of deleted ones? How can I resolve this issue? *** Sent via Developersdex http://www.developersdex.com ***
0
4906
by: BreckCogdill | last post by:
I have a problem with MS SQL Server 2005 - When I do an Import or Export to/from databases, the Identity is lost. I check the Enable Identity Insert box on each table, but it does not work. Is there a way to avoid having to manually modify each table to reset the Identity? Any assistance would be greatly appreciated, I support 50 some sites with database that all have over 200 tables, quite a pain! Thanks for your help . . .Breck Cogdill
0
9726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7667
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6887
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.