Connecting to MSSQL with out a DSN

Problem:

Connecting to MSSQL with out a DSN



Solution:

* You can use the following string to connect to MSSQL with out a DSN. It uses an OLEDB connection string to connect to a Microsoft SQL Server 200 database from within ASP:

<%
Dim conn

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open "Provider=SQLOLEDB; Data Source =mssql.server.com; Initial Catalog = mydatabase; User Id = USER; Password=PASSWORD; Network Library=dbmssocn;"

If conn.errors.count = 0 Then

Response.Write "Connected OK"

End If
%>


In the example above, mssql.server.com is the MSSQL server, USER is the username and PASSWORD is the password which was provided to you in your MSSQL account setup mail.

OLEDB connection strings have both advantages and disadvantages associated with using them. These are shown below:

Advantages:

  • Using OLEDB connection strings provides faster access to data when compared to system DSN's.
  • The parameters for the connection string can be stored in a separate file. This file can be included into multiple ASP scripts, meaning that only one change is necessary if we want to modify the connection strings parameters.
Disadvantages:
  • For beginners, it can often be hard to remember the syntax of a connection string. This has been the point of confusion for many developers trying to get a database connection to work properly. *

 

  • 0 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente?

Articles connexes

get "SQL Server does not exist or access is denied" error when I tried to connect to MS SQL database on your server?

Problem: get "SQL Server does not exist or access is denied" error when I tried to connect to MS...

Opening the Database Folder in SQL Server Enterprise Manager 2000 Takes a Long Time

Problem: Opening the Database Folder in SQL Server Enterprise Manager 2000 Takes a Long Time...

I'm getting a strange error message: Operation must use an updateable query(error '80004005')?

Problem: I'm getting a strange error message: Operation must use an updateable query(error...

error: Too few parameters

Problem: error: Too few parameters Solution: error type:Microsoft OLE DB Provider for ODBC...

What is the ports do SQL Server clients (Enterprise Manager, Query Analyser, etc) use?

Problem: What is the ports do SQL Server clients (Enterprise Manager, Query Analyser, etc) use?...