We are using sqlserver2005 at our liveserver. Due to some third party attacks which caused loss of data, we changed the sql user permission to only read,write and execute. Now, some of the sps in the db contain code to insert into identity column with line
SET IDENTITY_INSERT [tblName] ON
insert stmts...
SET IDENTITY_INSERT [tblName] OFF
This throwing error as
Cannot find the object "tblName" because it does not exist or you do not have permissions.
Which minimal permission can be given to get the above code work with identity insert on/off? We have removed the dbo permission due to external attacks.
I'm trying to transfer data between two 2005 databases using the import/export method. I set the Enable Identity insert to true - edit mappings option - on all the tables but I still get the ID set back to 1. I want to add some live data to an altered database structure, and I'm assuming the import/export tool is the way to do this.
I understand that minimal logging can occur on a non clustered indexed heap as long as [URL] ...
*not replicated
*tablock is used
*table is empty
The following test seems to contradict this
In the test I create a non indexed heap, insert some record and check the log, then repeat the test on an indexed heap.
The results suggest that even though the conditions for minimal logging into a indexed heap are met, minimal logging is not happening although it does happen on an non indexed heap. What am I doing wrong?
CREATE DATABASE logtest GO USE logtest GO CREATE TABLE test (field varchar(100)) GO CHECKPOINT
SQL Server 2005 anomoly? In SQL Server Management Studio I granted specific permissions to user "A" to do Select, Insert, Update, Delete on Table "B" - When I logged on as User "A" and attempted the Insert imto table "B" I got the following error: "Insert Permission Denied on Table B, Database C, Schema dbo" Is this a problem with the dbo schema?
Then I went back and created a stored proccedure "D" with the exact same Insert statement inside the procedure. I granted User "A" execute permission on the stored procedure "D". I then logged on as User A and executed Stored Procedure "D". No Problem - stored procedure executed fine with the Insert. I attempted the Insert statement again - straight SQL - as User "A" and got the same error as above ("Insert Permission Denied.....") Strange behavior - cannot do a SQL. Insert even though user has permissions but can execute a store procedure with the same Insert statement. What gives?
While I have learned a lot from this thread I am still basically confused about the issues involved.
.I wanted to INSERT a record in a parent table, get the Identity back and use it in a child table. Seems simple.
To my knowledge, mine would be the only process running that would update these tables. I was told that there is no guarantee, because the OLEDB provider could write the second destination row before the first, that the proper parent-child relationship would be generated as expected. It was recommended that I create my own variable in memory to hold the Identity value and use that in my SSIS package.
1. A simple example SSIS .dts example illustrating the approach of using a variable for identity would be helpful.
2. Suppose I actually had two processes updating these tables, running at the same time. Then it seems the "variable" method will also have its problems. Is there a final solution other than locking the tables involved prior to updating them or doing something crazy like using a GUID for the primary key!
3. We have done the type of parent-child inserts I originally described from t-sql for years without any apparent problems. (Maybe we were just lucky.) Is the entire issue simply a t-sql one or does SSIS add a layer of complexity beyond t-sql that needs to be addressed?
I want to insert a new record into a table with an Identity field and return the new Identify field value back to the data stream (for later insertion as a foreign key in another table).
What is the most direct way to do this in SSIS?
TIA,
barkingdog
P.S. Or should I pass the identity value back in a variable and not make it part of the data stream?
set nocount on insert into [order] (orderdate,deliverydate,status,Totalprice,customerID) values(2006-02-23,2006-02-23,'N',10000,10) (insert into temp (orderid)values(@@identity))
Major Error 0x80040E14, Minor Error 25569 > set nocount on insert into [order] (orderdate,deliverydate,status,Totalprice,customerID) values(2006-02-23,2006-02-23,'N',10000,10) (insert into temp (orderid)values(@@identity)) Invalid set option. [ Set option = nocount ]
Without Nocount:
insert into [order] (orderdate,deliverydate,status,Totalprice,customerID) values(2006-02-23,2006-02-23,'N',10000,10) (insert into temp (orderid)values(@@identity))
Major Error 0x80040E14, Minor Error 25501 > insert into [order] (orderdate,deliverydate,status,Totalprice,customerID) values(2006-02-23,2006-02-23,'N',10000,10) (insert into temp (orderid)values(@@identity)) There was an error parsing the query. [ Token line number = 4,Token line offset = 1,Token in error = ( ]
How do i get @@identity to work. I understand that @@identity only can be used in the sam insert session.
I am having some problems wit a form where i need to insert a record into a table and then get the id of the record i just inserted and use it to insert a record in another table for a many to many relationship. The code is below (I cut out as much as i could to make it more readable). The erro message i get is this: Error saving file ATLPIXOFC.txt Reason: System.Data.SqlClient.SqlException: Prepared statement '(@FileName varchar(13),@ i' expects parameter @FileID, which was not supplied. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microvit_Document_Product_Document_Add_v2.insertDocumentToDB() in e:inetpubwwwrootMicrovitDocumentProduct_Document_Add_v2.aspx.vb:line 127 at Microvit_Document_Product_Document_Add_v2.btnInsert_Click(Object sender, EventArgs e) in e:inetpubwwwrootMicrovitDocumentProduct_Document_Add_v2.aspx.vb:line 37
Protected Sub insertDocumentToDB() Dim myConnString As String = ConfigurationManager.ConnectionStrings("Master_DataConnectionString").ConnectionString Dim myConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(myConnString) Dim myCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand Dim myTransaction As System.Data.IDbTransaction = Nothing myCommand.Connection = myConnection myCommand.Parameters.Add(New SqlParameter("@FileName", SqlDbType.VarChar)) myCommand.Parameters.Add(New SqlParameter("@ProductID", SqlDbType.Int)) myCommand.Parameters.Add(New SqlParameter("@FileID", SqlDbType.Int, ParameterDirection.Output))
Hi, I am having problem in bulk update of a sql server table haning identity column from a datatable( has no identity column) using sqlbulkcopy. I tried several approaches, but it does not show any error nor is the table getting updated. But the identity value seems to getting increased every time. thanks. varun
I'm writing a web application invovled SQL 2005. I had granted SQL Server user rights to the ASPNET as the procedure described in MSDN (http://msdn2.microsoft.com/en-us/library/e2t54ss5.aspx) . Therefore, there's no problem of connection. But when I try to insert some data into the database, I met an exception told me that the INSERT permission is denied. I try the same mdf file on another computer while the insertation succeeded. So I'm wondering is anything difference in security settings between my computer and the one succeeded? I also try the sample database Northwind, but same problem occurred. I'm sure it is problem of security settings other than the .mdf file itself. The following is the detailed error information: Product: Microsoft Visual Studio Version: 8.0 LCID: 1033 Type: System.Data.SqlClient.SqlException Language: C# API: System.Data.SqlClient.SqlCommand.ExecuteNonQuery [Sytem.Data.SqlClient.SqlException]: "INSERT permission denied on object 'Employees', database 'Northwind', schema 'dbo'," ErrorCode: -2146232060 Class: 14 LineNumber: 1 Number: 229 Server: (local)SQLExpress State: 5 Message: INSERT permission denied on object 'Employees', database 'Northwind', schema 'dbo'
I've a data access code as below to insert two data into my sql server db. but there is an error occur. which permission is denied. before this i'd tried to read data from the dataase, it doesn't has any permission denied. Public Function newRegister(ByVal uName As String, ByVal uPass As String) As Boolean Dim valid As Boolean = False If findMember(uName) = False Then conRegister.Open()Dim sqlCmd As System.Data.SqlClient.SqlCommand = conRegister.CreateCommand() sqlCmd.CommandType = CommandType.Text sqlCmd.CommandText = "Insert into Logon (UserName, Password) Values(@UserName, @Password)"sqlCmd.Parameters.AddWithValue("@UserName", uName) sqlCmd.Parameters.AddWithValue("@Password", uPass)
sqlCmd.ExecuteNonQuery() conRegister.Close() valid = True End IfReturn valid End Function
My hosting company created a database for me a few day ago.
To make queries into a database,I made aspx page with textarea for query text and two radio buttons for select/insert.
I can create a table but if i make a SELECT or INSERT statement I get permission denied error.In that error database and owner data are the same as my database and user ID I use in a connection string. So why dont I have permissions?
I created an account in webmatrixhosting to test my application and there everything works just fine.
So I tried to use "sp_tables" query before I make any table.
On my hosting company I got nothing but in webmatrixhosting I get 16 rows of SYSTEM_TABLES and 2 rows of VIEWS.
Did my hosting company correctly set up my database? They say they did but I Im not so sure.
Have run to a select permission error when attempting insert data to a table. received the following error
Msg 229, Level 14, State 5, Line 11 The SELECT permission was denied on the object 'tableName', database 'DBname', schema 'Schema'.
Few things to note - There are no triggers depending on the table - Permissions are granted at a roll level which is rolled down to the login - The test environments have the same level of permission which works fine.
I'm just learning SSIS and I've hit my first bump. I am doing a bulk import from a tab delimited text file to an empty sql table that has a Idendity column defined. How do I tell the bulk insert task to skip that column when inserting from the text file. If I remove the identity column it imports the data fine, but I want to create the indentity column in the table too.
the 1st insertcommand works but the 2nd one does not. Shouldn't I be able to substitute a var in the parameter's place? Dim zid As String = Session("ID") SqlDataSource2.InsertCommand = "insert into cart (lmca_nbr,office,noun, price, quantity) values (?,?,?,?,?)" SqlDataSource2.InsertCommand = "insert into cart (lmca_nbr,office,noun, price, quantity) values (zid,?,?,?,?)" SqlDataSource2.Insert()
The smallest downloadable version seems to be 53MB. Is there any way to create a smaller version to use as an embedded DB for an application? I only need it to be single-user, for what that's worth. I'm thinking more in the 10MB to 20MB range.
When assigning permission to an authentication user to connect to a server database, if I want the user to be able to insert / update / delete data on db objects specifically tables, what permission should be assigned to that user?
My thoughts were Insert / Update / Delete; however, someone suggested that the Execute permission would do this ...
after i have inserted a row into the DB i am trying to get the last identity like this : Dim myCommand2 As New SqlCommand("SELECT @@IDENTITY AS 'Identity'", ) Dim myReader2 As SqlDataReader myReader2 = myCommand2.ExecuteReader() where myConnection2 is the connection objectafter i did this i dont underdsand how do i get the 'Identity' value?i tried myReader2 ('Identity') but no luckany 1 can helpthnaks in advancepeleg
Let me start off by saying I have posted this on: comp.databases.ms-sqlserver
My apologies, try not to do that again.
I have a table that I am trying to insert into with data from another table. Here is that Query:
INSERT INTO item (identifier, name, customlgtxt1, weight,mainprice, customnumber3, customnumber4) Select partno, name, description, weight,price, qtyprice, qty From Import2
This seems to work fine.
My dilemma has to do with an 'id' column in that item table. This is incrementally updated by one..ie Natural Key. I have set it to Identity and used Set @@IDENTITY AS 'id'...worked like a charm. But for reasons that have to do with a front end admin tool used by the home office I can't set this column to have an Indentity property. Screws up the insert done with the admin tool.
This is a item/price database by the way. Name of item, price, description, qty price..etc.
So I've tried to put this trigger on the item table CREATE TRIGGER auto_fill ON [dbo].[item] FOR INSERT, UPDATE AS BEGIN declare @maxc int set @maxc = (select Max(id) from item) set @maxc = @maxc +1 Select 'id' AS '@maxc', notorderable = '0', createdon = getdate(), createdat = getdate(), createdby = 'Steve', modifiedon = getdate(), modifiedat= getdate(), modifiedby = 'Steve'
END
But the Insert Into statement (see above) will not work...giving the error "Cannot insert the value NULL into column 'id', table 'new_Catalog1v1.dbo.item" Which I know...that's why I set it to Identity..but that cannot be.
So the question is how to set an autonumber (or natural key or I'm not sure of the name) that updated from the max(id)table when inserting from another table.
And then...one more.
I have to update a table named UNIQUEIDS with the lastest value of the id column (max(ID))..UNIQUEIDS keeps track of the latest value inserted into the id column for a number of tables. Here is another trigger I put on the item table to update the UNIQUEIDS table.
create trigger upUniqueIds_item on [dbo].[item] for update,Insert, delete as begin Select @@Identity as 'id' from inserted Update uniqueids set id = @@identity Where tablename = 'item' End
But of course this doesn't work if I can't set the columns to IDENTITY.
I hope someone can help and I hope my explanation had made sense. Need to increment the id field using max(id) and update another table with the last imported value of max(id). One occurs during insert..another after the insert..i think?
i have a question: i have a table that has an identity id column called pId and also a column called ParentPid. now my question is that i want to insert the value of pId into the ParentPid when i'm adding a new Property to a table. any idea? thanks
I need to send some long emails, problem is when I send a long body text CDO breaks up the message with spaces in the middle of words. I read on this forum the solution would be to insert CR/LF into the message so that CDO would not have to break it up at every 1k of text. I have tried using CHAR(13) as BOL suggests, but this is not doing as intended, it inserts a space and not the CR/LF I need.
Any suggestions how to insert CR/LF or why my installation is not responding to CHAR(13) is there some other escape code I could use?
I have bought SQL Server 2005 Standard Ed. which will be used only to host databases for different applications like WSUS, McAfee Protection Pilot and CA Brightstor ArcServer. I do not have intention to create corporate applications using SQL Server.
In fact, I am using the SQL Server as a "multiple MSDE database server"...
My question is what are the minimal components between the following features to install (as I do not not really what they are doing) : -SQL Server -Analysis Services -Reporting Services -Notification Services -Data Tranformation Services -Workstation Components
Hey, I've been having problems - when trying to insert a new row i've been trying to get back the unique ID for that row. I've added "SELECT @MY_ID = SCOPE_IDENTITY();" to my query but I am unable get the data. If anyone has a better approach to this let me know because I am having lots of problems. Thanks,Lang