0 down vote favorite
I'm working on C# linq-to-sql application over SQL Server 2008 mdf database. My database is not inside SQL server, but inside my project folder. My connection string is
<add name="WindowsFormsApplication1.Properties.Settings.OpticaConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory| \Optica.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
I'm using windows authentication to access SQL Server from C#, and the .mdf file is copied to the ouput folder each time the application is run.
I have a stored procedure to back up the database. Executing the procedure within SQL Server completes successfully, but when I try to call this procedure from C# the following error occurs "Database 'optica.mdf' does not exist. Make sure that the name is entered correctly. BACKUP DATABASE is terminating abnormally.". That's though the database name "optica.mdf" is not even a parameter for the procedure.
Here is my stored procedure
USE [OPTICA.MDF]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[Sp_OpticaDatabaseBackup]
@Path varchar(1024),
as
Begin
DECLARE @fileName VARCHAR(256)
DECLARE @fileDate VARCHAR(20)
SELECT @fileDate = replace(CONVERT(VARCHAR(20),GETDATE(),126),':','-')
SET @fileName = @Path + 'Pts_' + @fileDate + '.BAK'
BACKUP DATABASE [optica.mdf] TO DISK = @fileName
End
Any ideas? Thanks in advance.