Solved

How to fully access SQL server database?

Posted on 1998-08-20
2
198 Views
Last Modified: 2010-03-19
I built a SQL server database with MS-SQL 6.5. I want to use MS VC++ 5.0 to access the database, such as, add, retrieve, delete records and etc.

So, after I built the database within MS SQL server "Enterprise Manager", I setup "ODBC database source" within "ODBC(32bit)" in Control Panel. Then, I add a MFC class "Myrecord" based on "CRecordSet".

At first, in my VC++5.0 source code, I use "CRecordSet::Open()" to open the database (No any parameters in "Open()", as the MS example shows). Then, I use "CRecordSet::AddNew()" or "CRecordSet::Edit()"  and "CRecordSet::Update()" to add or modify records in the database. However, right after the program executes "AddNew()" or "Edit()", there is a dialog box poped up: "Recordset is read-only".

So, I can't add or modify records in the database that I built and setup. Is the problem within SQL server database, or within the VC++ problem? From the VC++ help, I know that using "CRecordSet:Open()" (without any parameters) mean that the opened database can be fully accessed. However, why did it show "RecordSet is read-only"?

BTW, when I built my VC++ project with the "File->New" MFC AppWizard (multiple Document), in the step 2 of 6, I choosed "Header files only".

Now, I can only retrieve the records in the database but not add or delete. However, I am eager to fully access the database. Could you please help me figure out the problem?

Thank you very much!

--
Datax
0
Comment
Question by:datax
2 Comments
 
LVL 9

Accepted Solution

by:
cymbolic earned 200 total points
ID: 1089653
Of course, you need appropriate user rights in the database and the table in order to modify or update on SQL Server.  If you have sufficient rights, another reason that a recordset will be marked not updateable is because your recordset is missing one of the required key fields.  Finally, your choice of the cursor type when you create the recordset will also effect whether or not the recordset is read-only.  Make sure you have set all the necessary options on opening your recordset.
0
 
LVL 4

Expert Comment

by:tomook
ID: 1089654
Some drivers and some classes default to a snapshot if you do not specify. I have not worked with SQL Server ODBC from C++, but I believe if you do not specify, you will get a snapshot.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now