Click here to Skip to main content
15,897,518 members

connection string and backup operation

lapiol asked:

Open original thread
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:

C#
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
Tags: C# 3.5

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900