Results 1 to 5 of 5

Thread: Osql

  1. #1
    Join Date
    Oct 2004
    Posts
    3

    Red face Unanswered: Osql

    Hi all.

    My first post here.

    I want to distriburte a msde database. When doing so, I also want to make a new login, make a user, make the user the dbowner of the database i installed.

    I found the Stored procedures I need to use, and I have tested that it works using OSQL.

    What I want to do now is to make this automatic. After installing the database the OSQL commands should be executed and no user interference should be necessary. How can that be done ?

    peet

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    through a *.bat file?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Oct 2004
    Posts
    3
    Quote Originally Posted by Brett Kaiser
    through a *.bat file?
    Ok, how ?

    From what I see I have to do the following :



    '**************** sample ********************

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    D:\>osql -S PEETSPC\PEETSQL -U sa
    Password:
    1> sp_attach_single_file_db "TEST","D:\DB\TEST.MDF"
    2> go
    New log file 'D:\DB\TEST_log.LDF' was created.
    1> exit

    D:\>osql -S PEETSPC\PEETSQL -U sa -d TEST
    Password:
    1> sp_addlogin test, mypass, TEST
    2> sp_adduser test, test, db_owner
    3> go
    1> sp_addlogin test, mypass, TEST
    2> go
    New login created.
    1> sp_adduser test, test, db_owner
    2> go
    Granted database access to 'test'.
    'test' added to role 'db_owner'.
    1> exit

    D:\>


    How can I do this using a bat file ?
    I know what a bat file is, but I do not see how I can get a bat file to do the above. Please help me out if you can :-)

    peet

  4. #4
    Join Date
    Oct 2004
    Posts
    3
    *bump*

    anyone ?

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    You need two separate files. The first one I'll calll test.sql will contain:
    Code:
    sp_attach_single_file_db "TEST","D:\DB\TEST.MDF"
    go
    
    USE TEST
    GO
    
    sp_addlogin test, mypass, TEST
    sp_adduser test, test, db_owner
    go
    
    sp_addlogin test, mypass, TEST
    go
    
    sp_adduser test, test, db_owner
    go
    The second file I'll call test.bat:
    Code:
    osql -S PEETSPC\PEETSQL -U sa - P myPass=123 -i test.sql -o test.rpt
    When you run the batch file, it will create the database, add the logins and users, and put the output into the test.rpt file for your reading pleasure.

    -PatP

Posting Permissions

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