ASP.NET using C# - How to Connect/Retrieve in database to web a

December 2016

Some people may be carrying out projects in ASP.NET and they may need help with connecting their database with ASP.NET. Likewise with retrieving in database to web application. A specific sequence must be followed with regards to the database and the retrieving process. Some programming knowledge is needed to able to carry out the steps. The answer below should provide the answers to the issues just mentioned.

Issue



I am doing my project work, and I have a problem. My project is in asp.net but I don't know how to connect the database in asp.net using c# and how to retrieve in database to web application.

Solution


Notice this line:
-> database. conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data source= @"path AccessFile.mdb";

It should be:
-> database. conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=AccessFile.mdb";

Other Connection String Sample.

Visual Basic]     
Public Sub CreateSqlConnection()     
Dim myConnection As New SqlConnection()     
myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30"     
myConnection.Open()     
End Sub 'CreateSqlConnection     

[C#]     
public void CreateSqlConnection()     
{     
SqlConnection myConnection = new SqlConnection();     
myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";     
myConnection.Open();     
}     

[C++]     
public:     
void CreateSqlConnection()     
{     
SqlConnection* myConnection = new SqlConnection();     
myConnection->ConnectionString = S"Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";     
myConnection->Open();     
}     

Note


Thanks to Wicket for this tip on the forum.

Related :

This document entitled « ASP.NET using C# - How to Connect/Retrieve in database to web a » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.