Avatar billede cooltie Nybegynder
09. juni 2001 - 21:05 Der er 2 kommentarer og
1 løsning

System DNS?

Hej

Hvordan opretter jeg en forbindelse til en database via en asp side/kode, som jeg har lavet en system DNS til i kontrolpanelet? Det er vigtigt at det er system DNS\'en i kontrolpanlet jeg bruger!
Avatar billede perla Nybegynder
09. juni 2001 - 22:04 #1
Prøv at se på denne artikel, den har jeg haft meget gavn af

http://www.asp101.com/articles/john/connstring/default.asp

Hvilken database kører du med?

-Per
Avatar billede Techwork Praktikant
09. juni 2001 - 22:50 #2
Mon ikke du mener DSN (Data Source Name) og ikke DNS (Domain Name Service).

Her er et lille eksempel. Det skal dog siges at det er op i mod en MS-SQL server. Det kan være at du kan bruge det som inspiration til at komme igang.

<%
Function MyDate()
    dteCurrent = Date()

    dteDay = Day(dteCurrent)
    dteMonth = Month(dteCurrent)
    dteYear = Year(dteCurrent)

    MyDate = dteDay & \"-\" & dteMonth & \"-\" & dteYear
End Function

Response.write \"<IMG src=\'logo2.gif\' border=0><BR><BR>\"
Response.write \"<FORM method=\'post\' action=\'edit.asp\'><input type=\'submit\' value=\'Tilføj Nyhed\'></FORM>\"
Response.write \"<HR>\"


    \'Init the dsn connection string
DIM svrName, dbName
svrName = \"JDPSQL\"
dbName = \"Internet\"
pswd = \"\"
login = \"sa\"
myDSN = \"PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=\"&svrName&\";DATABASE=\"&dbName&\";UID=\"&login&\";PWD=\"&pswd&\";\"

    mySql = \"select * from Nyheder ORDER BY nr DESC\"

    \'Init connection object and execute the query
    set conObj = Server.Createobject(\"adodb.connection\")
    conObj.open myDSN
    set rs = conObj.Execute(mySql)
   
    Response.write \"<TABLE border=\'0\' width=\'80%\'>\"
    Dim counter
    counter = 0

    Response.write \"<B><TR BGCOLOR=\'#606060\'>\"        \'<TD><font color=\'#FFFFFF\'><B>Nr</B></TD>\"
    Response.write \"<td><font color=\'#FFFFFF\'><b>Dato</b></td></FONT>\"
    Response.write \"<td><font color=\'#FFFFFF\'><b>Nyhed</b></td></FONT>\"
    Response.write \"<td><font color=\'#FFFFFF\'><b>Opdateret af</b></font></td></TR></B>\"
Do While (Not rs.EOF)
    counter = counter+1
    if counter mod 2 = 0 Then
        Response.Write \"<tr BGCOLOR=\'#AAAAAA\'>\"        \'<td>\" & rs(\"Nr\") & \"</td>\"
    else
        Response.Write \"<tr BGCOLOR=\'#FFFFFF\'>\"        \'<td>\" & rs(\"Nr\") & \"</td>\"
    end if
    Response.write \"<td>\" & rs(\"dato\") & \"</TD>\"
    Response.Write \"<td><FORM method=\'post\' action=\'nyheder.asp\'>\"
    Response.write \"<input type=\'hidden\' name=\'nr\' value=\'\" & rs(\"NR\") & \"\'><U>\"
    Response.write \"<div STYLE=\'cursor:hand;\'><a href onClick=\'submit()\'>\" & rs(\"Overskrift\") & \"</A></div></U></td>\"
    Response.Write \"<td align=\'center\'>\" & rs(\"INI\") & \"</td></tr></FORM>\"
    rs.MoveNext
Loop

    \'***********Response.Write \"Antal rækker.: \" & counter & \"\"
    Response.write \"</TABLE>\"   

    Set rsObj = NOTHING
conObj.close

    Response.write \"<A href=\'result.asp\'>Vis kun nye nyheder</A><BR>\"

%>
Avatar billede perla Nybegynder
09. juni 2001 - 23:13 #3
Præsis samme information står i den link jeg sendte dig.

DSN Connections
DSN connections store their connection information in the Windows Registry. Naturally it\'s not a good idea to have people poking around in the registry so in the Windows NT4 Control Panel you\'ll find an applet called \"ODBC Data Sources\" which provides a wizard like interface to collecting connection settings. In Windows 2000, it\'s been moved to the \"Administrative Tools\" Folder in the Control Panel and renamed \"Data Sources (ODBC)\", but it functions the same.

In a nutshell, it\'s only real functionality is to help you create a connection string, save these connection settings to the registry, and associate them with a unique DSN. If you\'re using DSNs for ASP, make sure they\'re System DSNs so that they\'re available for all users. Since these settings are all previously saved, the connection string becomes simplicity itself:

Provider=MSDASQL; DSN=data_source_name;
or since MSDASQL is the default, simply:

DSN=data_source_name;
If you need to, you can also specify username and password information, but the parameter names are slightly different then with OLE DB resulting in a fully qualified connection to a DSN that looks something like this:

Provider=MSDASQL; DSN=data_source_name; UID=username; PWD=password;
Any other parameters you need, including what driver to use and even what type of database to connect to, is set via the wizard-like setup in the DSN configuration utility in the control panel discussed earlier.

-Per
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester