| 
                
Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with. 
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | deedeeStarting Member
 
 
                                        3 Posts | 
                                            
                                            |  Posted - 2005-07-05 : 06:48:20 
 |  
                                            | Hi,My application does communicate with the SQL database using ODBC. I can read from it and browse. When I make a connection using access, using the same user adding records is possible.When I use my vb code it works fine until I try to add a new record and update. I get a message that the database does not allow this because of insufficient rights. This happens with the same user as mentioned above. Even the sa user has the same result.Does anyone know the solution or does anyone have some sample code how to write into an sql database using odbc?Deedee |  |  
                                    | deedeeStarting Member
 
 
                                    3 Posts | 
                                        
                                          |  Posted - 2005-07-05 : 07:41:01 
 |  
                                          | And this was my code which failedPrivate Sub Command1_Click()Set wspace = CreateWorkspace("ws", "user", "pw", dbUseODBC)Set conodbc = wspace.OpenConnection("user", dbDriverNoPrompt, False, "ODBC;database=ttx;UID=user;PWD=pw;dsn=ttx")Set rstodbc = conodbc.OpenRecordset("select * from etiket", dbOpenDynamic, 0, dbOpenDynaset)rstodbc.MoveFirstMsgBox rstodbc.Fields(1).Value 'this works finerstodbc.AddNew 'seems to work as wellrstodbc.Fields(1).Value = "test" 'odbc call fails runtime error 3146rstodbc.UpdateEnd Sub |  
                                          |  |  |  
                                    | AndrewMurphyMaster Smack Fu Yak Hacker
 
 
                                    2916 Posts | 
                                        
                                          |  Posted - 2005-07-05 : 09:19:44 
 |  
                                          | I think you're misunderstanding the contents of the recordset....it's a READONLY recordset....based on the statement "SELECT * from etc,etc"It's not the same as a direct-linked recordset to an access table....where the table is editable.You'll need to issue an "Insert into etiket (cola, colb, colc) values (a,b,c)" style statement to get the new data into the sql database. |  
                                          |  |  |  
                                    | deedeeStarting Member
 
 
                                    3 Posts | 
                                        
                                          |  Posted - 2005-07-07 : 03:26:01 
 |  
                                          | Thanks Andrew.I just found out that using the ADO object does the trick. I was using the dao. The procedure is the same as I used in my original code. Making selections did not make any difference.Deedee |  
                                          |  |  |  
                                    | jenMaster Smack Fu Yak Hacker
 
 
                                    4110 Posts | 
                                        
                                          |  Posted - 2005-07-08 : 05:07:13 
 |  
                                          | the reason why DAO failed is because after adding the row, you need to move the cursor from the one you've added so it will be saved,ADO automatically saves without moving the cursor--------------------keeping it simple... |  
                                          |  |  |  
                                    | jsmith8858Dr. Cross Join
 
 
                                    7423 Posts | 
                                        
                                          |  Posted - 2005-07-08 : 09:09:44 
 |  
                                          | Try to get out of the habit of opening recordsets (in either ADO or DAO) and updating or adding rows directly.It is much better practice (and in .NET the only way to do it) to use either stored procedures and/or parameterized INSERT statements and to call commands to add or change data in your tables.- Jeff |  
                                          |  |  |  
                                |  |  |  |  |  |