Jirr Meynor

Jirr Meynor

  • NA
  • 22
  • 0

Cannot find database

Nov 13 2011 9:01 AM
Hi,

I've created a database using this Stored Procedure.

ALTER PROCEDURE dbo.StoredProcedure1
    (
    @DatabaseName    VARCHAR(50) = 'SampleDB'
    )
AS
BEGIN
    SET NOCOUNT ON
    EXECUTE('CREATE DATABASE ' + @DatabaseName);
END

Executed it in ASP.net web page

SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=<local computer path>\App_Data\ssdb_main.mdf;Integrated Security=True;User Instance=True");

        con.Open();

        SqlCommand dbc = new SqlCommand("StoredProcedure1", con);
        dbc.CommandType = System.Data.CommandType.StoredProcedure;

        dbc.Parameters.Add(new SqlParameter("@DatabaseName", "MyNewSampleDB"));

        dbc.ExecuteNonQuery();

        con.Close();



It executed successfully but I cannot find the database. I rerun it and it says it that the database has already existed? Where can I find it? I tried in C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA AND C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA but the database is not in there..

Help anyone?

Thanks

Answers (6)

0
Sam Hobbs

Sam Hobbs

  • 54
  • 29.3k
  • 2.1m
Nov 14 2011 7:03 PM
Since your connection string has "Data Source=.\SQLEXPRESS" I assume it is a SQL Server Express database. I do have a database in my folder at:

C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA

Can you find the database in the server explorer in Visual Studio? Look at the properties there; what does it say for the connection string in the Server Explorer?
0
Rajkumar R

Rajkumar R

  • 0
  • 183
  • 220.9k
Nov 14 2011 7:12 AM
Hi
Default location of storing database is this C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\YOURDB.mdf
In this location all those databases present which are available and created in sql server. 
Your database will also be in this location
Check 
0
Kunal Naik

Kunal Naik

  • 0
  • 296
  • 0
Nov 14 2011 6:44 AM
Hi,

When ever we create the database in sql server then it will strore in following location of your system,

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\SampleDB.mdf

In this location all those databases present which are available and created in sql server.
Your database will also be present in this location.
0
Priya Linge

Priya Linge

  • 0
  • 4k
  • 989.5k
Nov 14 2011 12:07 AM
Hi,

Please try this,

C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA

Hope this will help you.

Thanks.
0
Jirr Meynor

Jirr Meynor

  • 0
  • 22
  • 0
Nov 13 2011 11:42 PM
Hi,

The database that I created is not in the APP_DATA folder of my project.

Thanks.

Jirr
0
Manoj Sevda

Manoj Sevda

  • 0
  • 993
  • 477.3k
Nov 13 2011 11:08 PM
Hi,

When you create a database as a attached then it could not be available at Sql server default path like in
"C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA" In this condition you can find SampleDB.mdf file in "App_Data" Folder in your application.