select physical_name from sys.database_files where type = 0
The above SQL query to execute. Below is the C # code that will retrieve and store this data in string :
SqlConnection DbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["CStringName"].ConnectionString); SqlCommand GetDataFile = new SqlCommand(); GetDataFile.Connection = DbConn; GetDataFile.CommandText = "select physical_name from sys.database_files where type = 0"; try { DbConn.Open(); string YourDataFile = (string) GetDataFile.ExecuteScalar(); DbConn.Close(); } catch (Exception ex) { DbConn.Dispose(); }
user596075
source share