Hi,
I am a programmer Italian, I do not know English well. I hope to explain my problem well.
I develop in C # on a PC with Windows Seven Pro, vs 2010 pro, sql server 2008.
I have problems with the backup operation and the connection string.
The code is as follows:
private void BK()
{
string strconn = @"Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = strconn;
try
{
//Query per backup
string queryBK = "BACKUP DATABASE db TO DISK ='C:\\Program Files\\Microsoft SQLServer\\MSSQL10.SQLEXPRESS\\MSSQL\\Backup\\db.bak' WITH INIT, SKIP, CHECKSUM";
//Creazione Command
SqlCommand cmdBK = new SqlCommand(queryBK, conn);
// Open connection.
conn.Open();
//Execute command
cmdBK.ExecuteNonQuery();
MessageBox.Show("backup effettuato");
}
catch (Exception ex)
{
// Process exception.
MessageBox.Show(ex.Message, "ERRORE", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
conn.Close();
}
}
This code works on the development PC, but if I install my application on another PC (with Vista) does not work, returned the following error:
"The database does not exist. Verify that the name has been entered correctly. INTERRUPTION
ANOMALOUS BACKUP DATABASE."
I would stress that this string works well with the operations INSERT, DELETE, UPDATE
on both my PC and on the PC test.
If I replace the connection string with:
string strconn = @"Data Source=.\SQLEXPRESS; Database = db;Trusted_Connection =True";
The string work on my PC but on my test computer returns the following error:
"Can not open database requested by the login. Login failed.
Login failed for user Pina-PC \ Pina "
Someone could help me to solve this problem?
Thanks...Iole
Loading

Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 7, 2011, 11:01 AM EDT
Please do not forget to mark "Accepted Answer".
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 7, 2011, 8:38 AM EDT
"Data Source=machinename\SQLEXPRESS;Initial Catalog=dbName;Integrated Security=True"
Please do not forget to mark "Accepted Answer".
Iole7 reputationPosted Oct 7, 2011, 9:55 AM EDT
Hi,
I use Windows Authentication.
I stored the connection string in app.config by referring to the link
http://msdn.microsoft.com/it-it/library/ms254978(v=vs.80).aspx.
Strangely, after this, the string
connectionString="Data Source=.\SQLEXPRESS; Database = db;Trusted_Connection =True"
providerName="System.Data.SqlClient" />
returns an error even on PC development :
(Impossibile aprire il database richiesto dall'account di accesso. Accesso non riuscito.
Accesso non riuscito per l'utente Iole-PC\Iole)
Can not open database requested by the login. Login failed.
Login failed for user Iole-PC \ Iole
I tried your suggestion but it returns the same error even on PC development.
Thank you for reply.
Iole
Sam HobbsRank #107 · 20.5K reputationPosted Oct 7, 2011, 8:50 PM EDT
So you can make a configuration option in your program that could be used to specify the database and other connection parameters and that connection string could be saved in the configuration file. Or you could write a separate program to do the configuration and store the connection string wherever it is convenient for you.
Iole7 reputationPosted Oct 9, 2011, 9:45 AM EDT
Yes, it fail at conn.Open();
If I use the connection string:
providerName="System.Data.SqlClient" />
...I returned the following error:
In this case it not fails on conn.Open(); but on ..
string
I hope you can help me solve this problem ..... thanks
queryBK = "BACKUP DATABASE dbSchedaPaziente TO DISK ='C:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQLEXPRESS\\MSSQL\\Backup\\db.bak'WITH INIT, SKIP, CHECKSUM";Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 9, 2011, 5:09 PM EDT
Iole7 reputationPosted Oct 10, 2011, 1:53 AM EDT
Unable to open the physical file "C:\Users\Iolanda\Documents\Visual Studio 2010\Projects\SchedaPaziente prova\SchedaPaziente\dbSchedaPaziente.mdf". Operating system error 32: "32(Can not access the file. The file is used by another process.)"
Abnormal termination of the current BACKUP DATABASE.
The only connection string that works on the development PC is as follows:
string strconn = @"Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";
......but strangely it does not work on the test PC!!!!!!!!!!
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 10, 2011, 2:45 AM EDT
//give your database name in Database Parameter
string strconn = @"Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\db.mdf;Database=db;Integrated Security=True;User Instance=True";
Also see this Post : Click Here