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=
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
Sam HobbsPosted Nov 14, 2011, 7:03 PM
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?
Rajkumar RPosted Nov 14, 2011, 7:12 AM
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
Kunal NaikPosted Nov 14, 2011, 6:44 AM
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.
Priya LingePosted Nov 14, 2011, 12:07 AM
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.
Jirr MeynorPosted Nov 13, 2011, 11:42 PM
The database that I created is not in the APP_DATA folder of my project.
Thanks.
Jirr
Manoj SevdaPosted Nov 13, 2011, 11:08 PM
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.