Results 1 to 7 of 7

Thread: building an SQLServer database

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    46

    building an SQLServer database

    I need to know how to connect to data in a database I create incode, in SQLServer. Does anyone know what I need in order to set the connection in runtime with the new database name?

    (I didn't mean to post duplicate threads, it happend because I sent my post when I weren't near the computer about mor then 15 minutes, and then you get the chance to write your user and passward again - what made me think my thread wasn't there. I didn't know it was there already.)
    Last edited by SuKaSa; Mar 1st, 2007 at 01:21 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: change name of connection to SQLServer on runtime

    To connect to any SQL Server database you need to assign the appropriate values to the ConnectionString property of an SqlConnection object. www.connectionstrings.com has the appropriate formats. If you want to build a connection string piece by then, assuming that you're using VB 2005, the easiest way is with an SqlConnectionStringBuilder.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    46

    Re: building an SQLServer database

    I did that before I even read your reply, and it works, thanks.
    Now I'm searching for a way to build relations between tables, this time in SQLServer. I've googled and so far had no luck.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: building an SQLServer database

    You create relations when you create the child table by specifying a constraint.

    http://msdn2.microsoft.com/en-us/library/ms174979.aspx

    I'd assume you can do an ALTER TABLE too after the fact but I've never done so.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    46

    Re: building an SQLServer database

    Thank you very much, I think this is what I'm looking for.

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    46

    Re: building an SQLServer database

    Look, I've tried using your link, and here's my query after trying:

    CREATE TABLE tbl_A({A_ID NUMBER CONSTRAINT fk_tbIA_tbIE_id (FOREIGN
    KEY REFERENCES tbl_E(E_ID) ON DELETE CASCADE ON UPDATE CASCADE), name char(1)} )

    CREATE TABLE tbl_E( { E_ID NUMBER, name char(1) } )

    It haas syntax errors. can you see them? I bet it refers to the parentheses.

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: building an SQLServer database

    You must create TBLE first - right?

    Also - get into Management Studio and put in that DDL statement - it will help you see you syntax errors better.

    Why are you creating a table from code?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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