Connect to MSSQL Database Using VB.NET or C#

Here you will find two code examples that show you how to connect to an MSSQL database with VB.NET or C#.

You will find the database connection details in 1&1 IONOS by selecting Hosting, then Manage from the MSSQL Databases section.

VB.NET

The example shows the use of the connection object in ADO:

Set ConnHandle = Server.CreateObject("ADODB.Connection")
ConnHandle.Open "driver={SQL Server};
server=db12345678.hosting-data.io;
uid=dbo12345678;
pwd=your_password;
database=db12345678";

Note: Replace the sample data for server, uid, pwd and database with those of your database.

For more information about using the connection object, see the Microsoft Developer Network (msdn): How Do I Use the Connection Object in ADO?

C#

In this example, a DSN Less connection is established via the SqlConnection object:

SqlConnection makeSQLConn = new SqlConnection("Persist Security Info=False;
server=db12345678.hosting-data.io;
Initial Catalog=db12345678; User ID=dbo12345678;
Password=your_password");

For more information about using the SqlConnection class, see the Microsoft Developer Network (msdn): SqlConnection Class