Click here to Skip to main content
13,197,796 members (43,467 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
Posted 6-Oct-11 4:36am
lapiol174
Updated 6-Oct-11 4:46am
Mehdi Gholam345.5K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

1) For you to backup a database then that database must exist on the other machine first.
You must have a db.mdf file in your application folder.

2) Integrated security works when your database server is working in Windows mode not in SQL server mode, so you are getting the 'Pina-PC\Pina' user does not exist or does not have access error.

use the following connection string :
string strconn = @"Data Source=.\SQLEXPRESS; Database = db;Trusted_Connection =True;integrated security = sspi;";
  Permalink  
Comments
Espen Harlinn 6-Oct-11 10:58am
   
Nice reply, my 5
Mehdi Gholam 6-Oct-11 11:02am
   
Cheers Espen.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171020.1 | Last Updated 6 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100