Crear conexión DSNLess

This may not be as big of a deal for many of you that are strictly using the Reporting features of SMS 2003 but if you are looking to do more advanced reporting from external data sources you might want to create a DSNless connection. Normally you'll need to either create a DSN on a web server to get a SQL connection working or modify your global.asa file. I don't do either of these. Here's what to do (this example will assume you want to build a connection string to a SQL server):

1. Create a file called "connect.udl" on your desktop or wherever.

2. Right-Click it and select "Properties".

3. On the 'Provider' tab select "Microsoft OLE DB Provider for SQL Server"

4. Go to the 'Connection' tab and fill out the Server name, user name and password which you wish to create the connection with (service accounts only please and local SQL accounts are better to use for security purposes) and the database to access. Click the check box for "Allow saving password". I'm using the SA account for the purposes of this demonstration but I suggest that you do not!

5. Click 'Test Connection' and you should see a "Test Connection Succeeded" message if all the server and credential information has been filled out successfully.

6. Click 'OK' to save the information.

7. Open the connect.udl file with notepad and you should see the following text:

[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Password=SAPassword;Persist Security Info=True;User ID=SA;Initial Catalog=Master;Data Source=SQLSERVER



Now you have built a successful connection string to use in an ASP page or VBScript to connect to a SQL server with. An example of connecting to an SMS database and grabbing all the records in the System_DATA table could be (in VBScript):



ConnStr = "SQLOLEDB.1;Password=SAPassword;Persist Security Info=True;User ID=SA;Initial Catalog=Master;Data Source=SQLSERVER"
SQL = "Select * From System_DATA"
Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open Connstr
objRS.CursorLocation = 3
objRS.Open SQL, objConn, 1, 1




This example might help more for most when creating external ASP pages than VBScripts, but you get the idea.



Fuente: http://www.myitforum.com/articles/19/view.asp?id=8600

No hay comentarios:

Publicar un comentario