CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2013
    Posts
    4

    Databases in Visual Studio 2012

    I have created a database in both Microsoft sql and in Visual Studio 2012 but I'm not sure how to connect to the database or run queries. I want this database to be local only, so it will always be on my system.
    Does anyone have any links/tutorials I could view? Google is not being my friend.

  2. #2
    Join Date
    Jul 2013
    Posts
    576

    Re: Databases in Visual Studio 2012

    If you want a "personal database" on your computer you could consider Microsoft Access,

    http://office.microsoft.com/en-us/access/

  3. #3
    Join Date
    Dec 2013
    Posts
    4

    Re: Databases in Visual Studio 2012

    I'm actually making a .dll for mIRC. I'd like to be able to store some information on a database and have the data available for view/manipulation during runetime.
    I guess my question is, if I make a database in Visual Studio 2012 and create queries for this database, how do I connect to the database and execute the queries I have created?

  4. #4
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: Databases in Visual Studio 2012

    Are you going to store large amounts of data? If not, you should really look elsewhere. SQL server is a heavyweight "enterprise" product.

    You could have a look at: SQLite and MongoDB

    If the amount of data is really small, another option is to store it in the windows registry.
    Nobody cares how it works as long as it works

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Databases in Visual Studio 2012

    If the amount of data is really small, another option is to store it in the windows registry.
    Have a look at using .ini files. See GetPrivateProfileString()/WritePrivateProfileString() or the other private profile functions.
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Another possibility would be to use xml. There are various free XML c++ libraries available.

    The choice really depends upon what you want to store and how much and how you want to access it.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Databases in Visual Studio 2012

    Quote Originally Posted by souly View Post
    I'm actually making a .dll for mIRC. I'd like to be able to store some information on a database and have the data available for view/manipulation during runetime.
    I guess my question is, if I make a database in Visual Studio 2012 and create queries for this database, how do I connect to the database and execute the queries I have created?
    Look at the CRecordset and CDatabase classes.

  7. #7
    Join Date
    Dec 2013
    Posts
    4

    Re: Databases in Visual Studio 2012

    Quote Originally Posted by GCDEF View Post
    Look at the CRecordset and CDatabase classes.
    Thanks I'll look into that and report back.

    As to the others I appreciate the help but I could potentially be storing information for thousands of users. If you think this is still small enough to use in .ini let me know. I kind of figured using a ini file would be slow and really painful for retrieving data from users.

    Edit:
    Im storing data in columns like this: user(str), floodControl, banned(bit), link(bit), points(int), wins(int), loses(int)
    this table will be accessed as long as a user is using the bot.
    Last edited by souly; December 12th, 2013 at 12:47 PM.

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Databases in Visual Studio 2012

    As to the others I appreciate the help but I could potentially be storing information for thousands of users. If you think this is still small enough to use in .ini let me know. I kind of figured using a ini file would be slow and really painful for retrieving data from users.
    Yes, for that volume of data.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Databases in Visual Studio 2012

    MS SQL Server Express Edition is a lightweight version of the well known "enterprise" product.

    Though MySQL 5 looks same applicable for the task of this size, and same free as well.

    SQLite is also fine for this, but not MongoDB which is non-SQL document oriented engine in contrast to true SQL engines above.
    Best regards,
    Igor

  10. #10
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Databases in Visual Studio 2012

    it also depends if you need to do inserts/updates/deletes in the data.

    if the data is static you have a lot more options available, including storing the data in const arrays in your code and compiling them into the exe.

    If you do need insert/updates/delete, then ini/registry is usable for a few Kb of data (more is inapropriate/slow), xml is feasible up until a few Mb. anything beyond needs some form of database. I'd look at a lightweight embedded solution like SQLite first.

    full databases are more complex to install, configure and set up, so this'll be an additional burden to your users, use it only if it really makes sense.

  11. #11
    Join Date
    Dec 2013
    Posts
    4

    Re: Databases in Visual Studio 2012

    Quote Originally Posted by OReubens View Post
    it also depends if you need to do inserts/updates/deletes in the data.

    if the data is static you have a lot more options available, including storing the data in const arrays in your code and compiling them into the exe.

    If you do need insert/updates/delete, then ini/registry is usable for a few Kb of data (more is inapropriate/slow), xml is feasible up until a few Mb. anything beyond needs some form of database. I'd look at a lightweight embedded solution like SQLite first.

    full databases are more complex to install, configure and set up, so this'll be an additional burden to your users, use it only if it really makes sense.
    So I had some time to work on this and I was able to successfully compile using SQLite however the dll no longer loads into mIRC. Could adding an additional library to the dll cause it to fail? I tried including my dll and sqlite3 lib files and even the sqlite3.dll in the mIRC folder but still no luck. This is the first dll I have made so I'm new to the subject.

    Also, if I create a database using my dll like so:
    Code:
    errHndlr = sqlite3_open_v2("test.db", &pDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    would the "test.db" be created at the location of my dll or at the location of the executable?
    Last edited by souly; December 18th, 2013 at 04:01 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured