Avatar billede javanewbie11 Nybegynder
12. august 2003 - 15:34 Der er 3 kommentarer og
1 løsning

Forbindelse til SQL Server

Hvordan skaber man forbindelse til en SQL Server?

Jeg tænker på koden her, ikke kliks i VS .NET...
Avatar billede medions Nybegynder
12. august 2003 - 15:39 #2
Du gør blot sådan her:

public DataSet Query(string query)
{
    OdbcConnection conn = new OdbcConnection("Driver={SQL Server};SERVER=localhost;UID=root;PWD=;DATABASE=test");
    OdbcDataAdapter adapter = new OdbcDataAdapter(query, conn);
    DataSet ds = new DataSet();
    adapter.Fill(ds, table);
    return ds;
}

//>Rune
Avatar billede avlund Nybegynder
12. august 2003 - 15:39 #3
http://www.connectionstrings.com/




Standard Security:
"Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"
  - or -
"Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False"
(both connection strings produces the same result)


Trusted Connection:
"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
  - or -
"Server=Aron1;Database=pubs;Trusted_Connection=True;"
  (booth connection strings produces the same result)

(use serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)


Connect via an IP address:
"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
(DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))


Declare the SqlConnection:

C#:
using System.Data.SqlClient;
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.ConnectionString="my connectionstring";
oSQLConn.Open();
Avatar billede avlund Nybegynder
12. august 2003 - 15:52 #4
Jeg takker for points. Elsker cut&paste.
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
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

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