Querying Microsoft SQL server 2005

This is a discussion on "Querying Microsoft SQL server 2005" within the Classic ASP section. This forum, and the thread "Querying Microsoft SQL server 2005 are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 24th, 2007, 16:44
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Querying Microsoft SQL server 2005

How do I do this with ASP.
I know how to do queries (SELECT * FROM whatever)
but how do I do this in ASP,
another words the equivalent of:
PHP: Select all

mysql_query("SELECT * FROM table_name") or die (mysql_error()); 

And how to setup Microsoft SQL Server Accounts to connect?
couldn't find any info on how to do this.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 27th, 2007, 22:24
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: Querying Microsoft SQL server 2005

the SQL doesn't change. what changes is how you connect to and retrieve the stuff from the database. The particular php code you have above connects to the local MySQL server (I believe).

In ASP, you will need to
a) create a recordset
b) connect to the database with a connection string
c) run your query
d) disconnect from the database

something like this:
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = " YOUR CONNECTION STRING HERE "
rs.Open " YOUR SQL HERE ", , adOpenForwardOnly, adLockReadOnly
Set rs.ActiveConnection = Nothing

That should get you started. Play with it and let me know how you get on...

Ps.: I typed this code straight in so forgive me if I make a mistake
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 27th, 2007, 22:44
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Querying Microsoft SQL server 2005

how do i find my connection string?
i don't know how to set up account
thanks for replying
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 28th, 2007, 07:12
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: Querying Microsoft SQL server 2005

Alex, do you know anything about MSSQL or MySQL?
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Sep 28th, 2007, 08:11
Up'n'Coming Member
Join Date: Sep 2007
Location: Wales, UK
Age: 36
Posts: 88
Thanks: 1
Thanked 0 Times in 0 Posts
Re: Querying Microsoft SQL server 2005

Here's a MSSQL 2005 connection string -

MM_connDN_STRING = "Provider=MSDASQL; Driver={SQL Server}; Server=SERVERNAME_OR_IP_ADDRESS; Database=DATABASE_NAME; User ID=DATABASE_USERNAME; Password='PASSWORD';"

Are you using Dreamweaver or are you hand coding?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Sep 28th, 2007, 08:13
Up'n'Coming Member
Join Date: Sep 2007
Location: Wales, UK
Age: 36
Posts: 88
Thanks: 1
Thanked 0 Times in 0 Posts
Re: Querying Microsoft SQL server 2005

if you are just learning ASP i would suggest cutting your teeth using MS Access and then change the DB and connection string when you know how MS SQL is setup with users and permissions.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Sep 28th, 2007, 08:23
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: Querying Microsoft SQL server 2005

As Robbie suggested, if you're just starting off you're better off playing around with Access.
Once you've grasped the concepts of databases you can start using 'real' databases like MSSQL & MySQL.
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Sep 28th, 2007, 08:44
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Querying Microsoft SQL server 2005

Maybe this will help.

ConnectionString
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Sep 28th, 2007, 15:52
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Querying Microsoft SQL server 2005

No i can query mysql fine with PHP.
But i wanted to use an mssql database for use with PHP, ASP.NET and C#
that way i can have a multplatform program.
What i really need help with is setting up mssql accounts.
I don't know how to do it
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Sep 28th, 2007, 16:03
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: Querying Microsoft SQL server 2005

"setting up mssql accounts" doesn't really explain it well.
Do you mean setting up a hosting account with a hosting company that offers MS hosting and MS SQL databases?
- OR -
Do you mean installing MSSQL Server on your machine and creating databases?

Either way, you will need this:
Microsoft SQL Server: SQL Server 2005 Express Edition
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Sep 28th, 2007, 16:09
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Querying Microsoft SQL server 2005

Quote:
Originally Posted by spinal007 View Post
"setting up mssql accounts" doesn't really explain it well.
Do you mean setting up a hosting account with a hosting company that offers MS hosting and MS SQL databases?
- OR -
Do you mean installing MSSQL Server on your machine and creating databases?

Either way, you will need this:
Microsoft SQL Server: SQL Server 2005 Express Edition
I've got that.
okay, you know in mySQL you need to use mysql_connect() with your host, username and password.
How do you do that with mssql?
I want to know how to connect to the mssql database which is on my server, via PHP.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Sep 29th, 2007, 12:04
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: Querying Microsoft SQL server 2005

Google is your best friend.
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Sep 29th, 2007, 12:09
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Querying Microsoft SQL server 2005

That's what I've been trying to do.
But i don't know how to find this out:
Quote:
Parameters


servername The MS SQL server. It can also include a port number. e.g. hostname,port.
username The username.
password The password.
new_link If a second call is made to mssql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. This parameter modifies this behavior and makes mssql_connect() always open a new link, even if mssql_connect() was called before with the same parameters.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Sep 29th, 2007, 13:03
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: Querying Microsoft SQL server 2005

server name - "(local)"
username and password - depends on what you chose when you installed your server. The default may be username "sa" with an empty password.

If you can't work it out, get MSSQL 2005 Management Studio Express and create yourself a login. The program itself will use Windows authentication to access the database so you won't need username/password to use it.
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Sep 30th, 2007, 01:28
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Querying Microsoft SQL server 2005

will try that and get back to you
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
question about querying 2 databases in php sudhakararaog PHP Forum 1 Mar 11th, 2008 19:33
Trouble connecting to Sql Server 2005 Management Studio Express? annawilsonz Databases 0 Sep 14th, 2007 06:30
Multi user support for SQL Server Express 2005 ish Databases 1 May 9th, 2007 16:51
Querying Dates Steve Mellor Databases 1 Apr 13th, 2007 14:59
Form Element has no properties when querying antonyx JavaScript Forum 13 Aug 25th, 2006 14:06


All times are GMT. The time now is 21:13.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved