How to create sql server database file from VB6 application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MartinJackson
    New Member
    • Dec 2009
    • 2

    How to create sql server database file from VB6 application

    Using SQL Server 2005 Express.

    I want to create and maintain the SQL database and tables from within a VB6 application. First I need to create an empty database file. This I can't do.

    Using
    Set mcn = New ADODB.Connectio n
    mcn.Open mstrConnectStri ng

    I have tried various connection strings -
    mstrConnectStri ng="server=(loc al)\SQLEXPRESS; " & "integrated security=sspi;d atabase=;"

    mstrConnectStri ng="Data Source=.\SQLEXP RESS;AttachDbFi lename=" & "xxx.mdf" & ";Integrate d Security=True;C onnect Timeout=30;User Instance=True"
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Connection string is used to used to connect to an existing database not to create a new one.

    Comment

    • vb5prgrmr
      Recognized Expert Contributor
      • Oct 2009
      • 305

      #3
      First, you need to have Administrative Rights to the database engine ("SA"). This includes read, write, create, delete. Then, you do not connect to any particular database but if you must connect to a database then connect to the MASTER database. Then you will need to execute a CREATE DATABASE statement, followed by CREATE TABLE statements...

      Create database syntax for SQL Server and all SQL Database Engine platforms.


      Use the pane on the left to navigate to the CREATE TABLE statement, and you may want to look at the CREATE INDEX and CREATE PROCEDURE if you are wanting to create stored procedures.

      So, you process would go like this...

      Connect to MASTER
      CREATE DATABASE
      USE DATABASE_NAME 'to switch to the database you just created
      CREATE TABLE
      CREATE INDEX
      CREATE PROCEDURE
      then if you are wanting to insert data into the database, use the INSERT STATEMENT or if you have created a stored procedure us it...



      Good Luck

      Comment

      • MartinJackson
        New Member
        • Dec 2009
        • 2

        #4
        My problem is to get connected so I can create my SS db from the VB6 application.

        The answer I needed was how to connect so I could run the SQL create DB.
        Your answer is Database=Master ;
        The rest is -

        ConnectionStrin g = "Provider=SQLNC LI;Server=YourS erverName;Datab ase=Master;Inte grated Security=SSPI;"

        Many thanks

        Comment

        • vb5prgrmr
          Recognized Expert Contributor
          • Oct 2009
          • 305

          #5
          Yes, just be careful to not make any changes to the MASTER database because if you do, you could ruin the entire installation or DBMS...



          Good Luck

          Comment

          Working...