What are the methods for asp.net to get the local database?
The main content of this article is to explain "what are the methods for asp.net to get the local database". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the ways for asp.net to get the local database?"
The copy code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
/ / method 1
System.Data.DataTable table = System.Data.SqlClient.SqlClientFactory.Instance.CreateDataSourceEnumerator () .GetDataSources ()
GridView1.DataSource = table
GridView1.DataBind ()
/ / get the local
Foreach (System.Data.DataRow row in table.Rows)
{
If (row [0] .ToString () .ToUpper () .Equals (System.Net.Dns.GetHostName () .ToUpper ()
{
Response.Write ("" + row [1])
}
}
/ / method 2
/ / need to refer to Microsoft.SqlServer.Smo.dll
GridView2.DataSource = Microsoft.SqlServer.Management.Smo.SmoApplication.EnumAvailableSqlServers (true)
GridView2.DataBind ()
}
At this point, I believe that you have a deeper understanding of "what are the methods of asp.net getting the local database?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!