none
Setup Does Not Run Other PC RRS feed

  • Question

  • Hi;

    i create a program with SQL but program setup not working on another computer.

    i think my connectionstring wrong. Or i making another mistake.

    i tested this command

    1-SqlConnection baglanti = new SqlConnection("Data Source=MY-PC-NAME;Initial Catalog=databasename;Integrated Security=True;");
            
    2-SqlConnection baglanti = new SqlConnection("Data Source=.;Initial Catalog=databasename;Integrated Security=true");
            
    3-SqlConnection baglanti = new SqlConnection("Server=.\\SQLExpress;AttachDbFilename=|DataDirectory|personelbilgi.mdf;Database=databasename;Trusted_Connection = Yes;");
    
    4-SqlConnection baglanti = new SqlConnection(@"Data Source =.\SqlExpress; Initial Catalog = databasename; Integrated Security = true");
    
    5-SqlConnection baglanti = new SqlConnection ("Data Source =.\\SQLExpress;Initial Catalog = databasename; User ID = sa; Password=1071");
    
    


    Other Pc;

    Netframework = OK

    SQL Server Service = Working

    Error Message

    A network-related or instance-specific error occurred while establishing a connection to the server. The server could not be found or the server could not be accessed. Verify that the instance name is correct and that SQL Server allows remote connections.(provider: Named Pipes Provider, error: 40 -Could not open connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005):The system cannot find the file specified.

    this command is not working

    SqlConnection baglanti = new SqlConnection("Data Source=OTHER-PC-NAME;Initial Catalog=databasename;Integrated Security=True;");
    

    I try  this command but is not working. i confused.

    How can i solve?


    Thank you for help. 

    Monday, January 28, 2019 8:03 AM

Answers

  • The connection string you posted is for the sysadmin account. You really don't want to use that one. Irrelevant the login fails so that tells me your password isn't valid most likely.

    Let's skip to the chase. Does your app need a database to work? Does each install of the app need a separate database (e.g. installing on machine A needs a separate database from machine B)? 

    If you need a database and each install needs its own database then you  should be using an in-memory database like SQLite, SQL CE or similar. SQL Server isn't the best option here. If you want multiple machines to use the same database then you'll need to put your database on a machine running SQL Server that both machines have access to.

    In your connection string you are using SQLEXPRESS. This isn't installed on a machine by default. If your app needs its own database then you can  use SQL Express but your installer needs to ensure it is installed. Alternatively you can provide your users the option of installing SQL Express or using a full SQL Server instance. Installing SQL Server will require the user to license and install it. Note that SQL Express is designed for local apps and development so it isn't something you'd install and try to use on a different machine.

    If you just need to store data then consider using something other than SQL. Files or an in-memory database would be the better option.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by HakanxYildiz Thursday, January 31, 2019 5:13 AM
    Wednesday, January 30, 2019 7:46 PM
    Moderator
  • Well, originally there is only "PCNameOrAddress" part and no "SQLServerInstance" part, so the client programs will connect to port 1433 of "PCNameOrAddress".

    Since SQL2005, the support for multiple instance is added. When "SQLServerInstance" exists, the SQL connector will query SQLBrowser of that machine for port number and use it instead if supplied. When "SQLServerInstance" is not supplied it'll still attempt to connect to port 1433 which now is known as "default instance". So the old convension of specifying SQL server is still valid.

    Btw, before we talk about this, I think the asker have a problem in understanding whether he want to connect to SQL server or SQLExpress. No further help can be given until he make this part clear. (Most likely SQL server because "SQL Server Service = Working", but still, lots of important detail not given, especially given "Integrated Security=true" is used here)




    Tuesday, January 29, 2019 10:14 AM
    Answerer
  • Thank you for all reply.

    i use google translate for understand :) 

    if you use code for explain i can understand.

    i understand this:

    my connectionstring wrong.

    because i didn't use InstanceName or PcName?

    but i think this code is true:

     SqlConnection con = new SqlConnection(@"Data Source =(PCNAME or .\InstanceName ; Initial Catalog = DBName; Integrated Security = true");

    this code isn't work. error message is :

    System.Data.SqlClient.SqlException (0x80131904): Cannot open database "Demo" requested by the login. The login failed.
    Login failed for user 'PcName\Administrator'.

    NOTE:

    I don't use this program in internet or local network. I use only desktop.

    I use only data entry/delete

    ---------------------

    That's great it works on your machine but that doesn't mean it works on another machine. Based upon your connection string you are attempting to connect to the SQL Server instance on the machine running your app. Does the machine you installed your app onto have SQL? Then you're using integrated security so the user who runs your app has to have login rights to that SQL instance. Based upon the error that is failing. You need to run SSMS on the machine you're having issues with and try to connect using the account your app is running under. Based upon the error you were trying to run the app as the local Administrator. Does your SQL server instance, running on that machine, allow access to the Demo database for that user account? The SQL error is telling you that Administrator does not have access to the Demo database on that server.
    Michael Taylor http://www.michaeltaylorp3.net

    Seeing your connection and simplifying what CoolDadTx said:

    You're using default instance (local), in other words you're using an local user from where the SQL Server instance is, this works well, because that local user has permissions to do things.

    Since you're trying to use the other machine to access the db, the server was expecting that the local user from the other machine had permissions, since he doesn't, it says : Well, the connection is ok, but you're not allowed to access.

    Well, for the other computer, it must access the server in name of "someone" with this "someone" permissions, so you must use have a user with permissions to do so and specify this user in there (as CoolDadTx also said) 

    BP-LP 2005/2016 @ll rights reserved



    Wednesday, January 30, 2019 4:28 PM

All replies

  • Data source needs to be the name of the SQL Server instance, not the machine name necessarily. The specific error you're showing indicates you're trying to use named pipes. You need to ensure both the remote server is configured to allow this.

    This question seems more related to getting SQL running on the remote machine. Can you connect to the remote server from the local machine using SSMS? Can you connect to the remote server from the local machine using SQL Server Object Explorer in Visual Studio. You can get the valid connection string from them. 


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, January 28, 2019 4:58 PM
    Moderator
  • Hi RavBanaag,

    Thank you for posting here.

    According your issue, you want to make the command work.

    >>The system cannot find the file specified.

    Based on the error that you provided, you could check if your database path is correct.

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 29, 2019 7:37 AM
    Moderator
  • Hi;

    i create a program with SQL but program setup not working on another computer.

    i think my connectionstring wrong. Or i making another mistake.

    i tested this command

    1-SqlConnection baglanti = new SqlConnection("Data Source=MY-PC-NAME;Initial Catalog=databasename;Integrated Security=True;");
            
    2-SqlConnection baglanti = new SqlConnection("Data Source=.;Initial Catalog=databasename;Integrated Security=true");
            
    3-SqlConnection baglanti = new SqlConnection("Server=.\\SQLExpress;AttachDbFilename=|DataDirectory|personelbilgi.mdf;Database=databasename;Trusted_Connection = Yes;");
    
    4-SqlConnection baglanti = new SqlConnection(@"Data Source =.\SqlExpress; Initial Catalog = databasename; Integrated Security = true");
    
    5-SqlConnection baglanti = new SqlConnection ("Data Source =.\\SQLExpress;Initial Catalog = databasename; User ID = sa; Password=1071");
    


    Other Pc;

    Netframework = OK

    SQL Server Service = Working

    Error Message

    A network-related or instance-specific error occurred while establishing a connection to the server. The server could not be found or the server could not be accessed. Verify that the instance name is correct and that SQL Server allows remote connections.(provider: Named Pipes Provider, error: 40 -Could not open connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005):The system cannot find the file specified.

    this command is not working

    SqlConnection baglanti = new SqlConnection("Data Source=OTHER-PC-NAME;Initial Catalog=databasename;Integrated Security=True;");

    I try  this command but is not working. i confused.

    How can i solve?


    Thank you for help. 


    It seems that the the SQL instance isn't there.

    Usually I use  "PCNameOrAddress"\"SQLServerInstance", I only see there the PC name.

    Go back to the source code, create a simple console app, with that same connection string and inside a try catch, test the connection on both PC.

    try {
    
     using(SqlConnection conn = new SqlConnection(cs)) {
            conn.Open(); 
        }
    
    }catch (Exception ex){
    
    Console.WriteLine(ex.Message);
    }

    Something like that.

    BP-LP 2005/2016 @ll rights reserved

    Tuesday, January 29, 2019 9:38 AM
  • Well, originally there is only "PCNameOrAddress" part and no "SQLServerInstance" part, so the client programs will connect to port 1433 of "PCNameOrAddress".

    Since SQL2005, the support for multiple instance is added. When "SQLServerInstance" exists, the SQL connector will query SQLBrowser of that machine for port number and use it instead if supplied. When "SQLServerInstance" is not supplied it'll still attempt to connect to port 1433 which now is known as "default instance". So the old convension of specifying SQL server is still valid.

    Btw, before we talk about this, I think the asker have a problem in understanding whether he want to connect to SQL server or SQLExpress. No further help can be given until he make this part clear. (Most likely SQL server because "SQL Server Service = Working", but still, lots of important detail not given, especially given "Integrated Security=true" is used here)




    Tuesday, January 29, 2019 10:14 AM
    Answerer
  • Well, originally there is only "PCNameOrAddress" part and no "SQLServerInstance" part, so the client programs will connect to port 1433 of "PCNameOrAddress".

    Since SQL2005, the support for multiple instance is added. When "SQLServerInstance", the SQL connector will query SQLBrowser of that machine for port number and use it instead if supplied. When "SQLServerInstance" is not supplied it'll still attempt to connect to port 1433 which now have the name "default instance".

    Btw, before we talk about this, I think the asker have a problem in understanding whether he want to connect to SQL server or SQLExpress. No further help can be given until he make this part clear. (Most likely SQL server because "SQL Server Service = Working", but still, lots of important detail not given, especially given "Integrated Security=true" is used here)


    Didn't know that.
    My connection always was PCName\SQLInstance I never used it differently, since it always worked.

    BP-LP 2005/2016 @ll rights reserved

    Tuesday, January 29, 2019 10:24 AM
  • Thank you for all reply.

    i use google translate for understand :) 

    if you use code for explain i can understand.

    i understand this:

    my connectionstring wrong.

    because i didn't use InstanceName or PcName?

    but i think this code is true:

     SqlConnection con = new SqlConnection(@"Data Source =(PCNAME or .\InstanceName ; Initial Catalog = DBName; Integrated Security = true");
    

    this code isn't work. error message is :

    System.Data.SqlClient.SqlException (0x80131904): Cannot open database "Demo" requested by the login. The login failed.
    Login failed for user 'PcName\Administrator'.

    NOTE:

    I don't use this program in internet or local network. I use only desktop.

    I use only data entry/delete

    Wednesday, January 30, 2019 12:41 PM
  • There indicates the server is now being found but the login you're using is invalid. The user name is given and it is a local admin account. If you're connecting to a remote server then that call would fail. Use a login that can connect to the remote server and try again. You can test the user account using SSMS to make sure it is valid.

    //Specify a user
    "Server=.\SQL;Database=MyDatabase;User Id=MyUser;Password=mypassword"


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, January 30, 2019 1:36 PM
    Moderator
  • CoolDadTx;

    i testing use ssms in my pc. ConnectionString working. Program working. All connectionString working in my pc.

    i don't try remote connection. 

    i create a program and build setup.msi. And run setup.msi on other PC. Setup completed but connection doesn't work.

    try this code :(

    Server=.\SQL;Database=MyDatabase;User Id=MyUser;Password=mypassword


    Wednesday, January 30, 2019 2:27 PM
  • That's great it works on your machine but that doesn't mean it works on another machine. Based upon your connection string you are attempting to connect to the SQL Server instance on the machine running your app. Does the machine you installed your app onto have SQL? Then you're using integrated security so the user who runs your app has to have login rights to that SQL instance. Based upon the error that is failing. You need to run SSMS on the machine you're having issues with and try to connect using the account your app is running under. Based upon the error you were trying to run the app as the local Administrator. Does your SQL server instance, running on that machine, allow access to the Demo database for that user account? The SQL error is telling you that Administrator does not have access to the Demo database on that server.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, January 30, 2019 3:07 PM
    Moderator
  • Thank you for all reply.

    i use google translate for understand :) 

    if you use code for explain i can understand.

    i understand this:

    my connectionstring wrong.

    because i didn't use InstanceName or PcName?

    but i think this code is true:

     SqlConnection con = new SqlConnection(@"Data Source =(PCNAME or .\InstanceName ; Initial Catalog = DBName; Integrated Security = true");

    this code isn't work. error message is :

    System.Data.SqlClient.SqlException (0x80131904): Cannot open database "Demo" requested by the login. The login failed.
    Login failed for user 'PcName\Administrator'.

    NOTE:

    I don't use this program in internet or local network. I use only desktop.

    I use only data entry/delete

    ---------------------

    That's great it works on your machine but that doesn't mean it works on another machine. Based upon your connection string you are attempting to connect to the SQL Server instance on the machine running your app. Does the machine you installed your app onto have SQL? Then you're using integrated security so the user who runs your app has to have login rights to that SQL instance. Based upon the error that is failing. You need to run SSMS on the machine you're having issues with and try to connect using the account your app is running under. Based upon the error you were trying to run the app as the local Administrator. Does your SQL server instance, running on that machine, allow access to the Demo database for that user account? The SQL error is telling you that Administrator does not have access to the Demo database on that server.
    Michael Taylor http://www.michaeltaylorp3.net

    Seeing your connection and simplifying what CoolDadTx said:

    You're using default instance (local), in other words you're using an local user from where the SQL Server instance is, this works well, because that local user has permissions to do things.

    Since you're trying to use the other machine to access the db, the server was expecting that the local user from the other machine had permissions, since he doesn't, it says : Well, the connection is ok, but you're not allowed to access.

    Well, for the other computer, it must access the server in name of "someone" with this "someone" permissions, so you must use have a user with permissions to do so and specify this user in there (as CoolDadTx also said) 

    BP-LP 2005/2016 @ll rights reserved



    Wednesday, January 30, 2019 4:28 PM
  • i understand my mistake. thanks for good explanation.

    my mistake permission setups.

    i try last cs is 

    Data Source =.\SQLEXPRESS; Initial Catalog = Demo; Integrated Security = False; User ID=sa; Password=1071

    error this login failed for "sa"


    i search how can i add user and password and tried all solution. but i cant solved :/

    maybe i cant to integrate my dbo in my project


    if i setup in other pc sql server management studio and create dbo.Demo and DemoTable, my program is working. 

    Have I to do this again on every computer?

    thank you for all reply again. Turkish Msdn didn't answer much as you.

    i trying for a soliton 5-6 days

     i give up sql. i try another database


    Wednesday, January 30, 2019 7:24 PM
  • The connection string you posted is for the sysadmin account. You really don't want to use that one. Irrelevant the login fails so that tells me your password isn't valid most likely.

    Let's skip to the chase. Does your app need a database to work? Does each install of the app need a separate database (e.g. installing on machine A needs a separate database from machine B)? 

    If you need a database and each install needs its own database then you  should be using an in-memory database like SQLite, SQL CE or similar. SQL Server isn't the best option here. If you want multiple machines to use the same database then you'll need to put your database on a machine running SQL Server that both machines have access to.

    In your connection string you are using SQLEXPRESS. This isn't installed on a machine by default. If your app needs its own database then you can  use SQL Express but your installer needs to ensure it is installed. Alternatively you can provide your users the option of installing SQL Express or using a full SQL Server instance. Installing SQL Server will require the user to license and install it. Note that SQL Express is designed for local apps and development so it isn't something you'd install and try to use on a different machine.

    If you just need to store data then consider using something other than SQL. Files or an in-memory database would be the better option.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by HakanxYildiz Thursday, January 31, 2019 5:13 AM
    Wednesday, January 30, 2019 7:46 PM
    Moderator
  • i understand my mistake. thanks for good explanation.

    my mistake permission setups.

    i try last cs is 

    Data Source =.\SQLEXPRESS; Initial Catalog = Demo; Integrated Security = False; User ID=sa; Password=1071

    error this login failed for "sa"


    i search how can i add user and password and tried all solution. but i cant solved :/

    maybe i cant to integrate my dbo in my project


    if i setup in other pc sql server management studio and create dbo.Demo and DemoTable, my program is working. 

    Have I to do this again on every computer?

    thank you for all reply again. Turkish Msdn didn't answer much as you.

    i trying for a soliton 5-6 days

     i give up sql. i try another database



    Don't give up yet.
    Watch this, and this d

    Read this for mor knowledge

    Do this: 

     eXEC sp_addlogin 'theUser', 'userpassword'

    DB Query

    create database TrabalhoDB;
    
    use TrabalhoDB;
    
    create table Employee(
    id  int identity(1,1) primary key,
    [name] varchar(30) not null, /*I think sql won't accept "name" as attribute */
    birhdate varchar(30) not null,
    workdate varchar(30) not null
    )
    I forgot how to comment on ms sql, to much MySQL these days, so I'm not sure if that is a comment lol



    Change SQL Server properties to allow Connection through both methods (local and SQL Server Authentication), I don't have SQL Server installed, so I can't show you this now.
    PS: Before going to C#, just for the sake of things.

    Try to login with the user and make some queries. If all work, there's all ok
    Try this above, change the connection string to the created user credentials, read this 

     SqlConnection connectionString = new SqlConnection(@"Data Source=ZUSS\SQLEXPRESS;Initial Catalog=TrabalhoBD;Integrated Security=True");
            SqlCommand command;
            SqlDataReader dataReader;
    
            private bool connectionState = false;
    
    
    
    
            public void InsertEmployee(string name, string address, string gender, string birthDate, string workDate)
            {
                string sqlQuery = "insert into Employee(Name, Adress, Gender, BirthDate, WorkDate) values('"
                    + name + "','" + address + "','" + gender + "','" + birthDate + "','" + workDate + "')";
    
    
                try
                {
    
                    connectionString.Open();
                    connectionState = true;
    
                    command = new SqlCommand(sqlQuery, connectionString);
                    command.ExecuteNonQuery();
    
                    connectionString.Close();
                    connectionState = false;
    
                }
                catch (Exception ex)
                {
                    if (connectionState == true)
                    {
                        connectionString.Close();
                        connectionState = false;
                    }
    
                    System.Windows.Forms.MessageBox.Show(ex.Message, "Error on insert");
                }
    
    
    
            }
    
    
    
    
            /* ---------------------------------------------------------*/
            public void GetEmployeeById( int id) 
            {
                
                string sqlQuery = "select name, address, gender from   employee  where " + id + "=" + id;
                
    
                int i = 0;
                try
                {
                    connectionString.Open();
                    connectionState = true;
                    command = new SqlCommand(sqlQuery, connectionString);
                    dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
    
                    if (dataReader.HasRows == true)
                    {
    
                        while (dataReader.Read())
                        {
    
                          
    
                            textBox1.Text = dataReader["name"].ToString();
                            textBox2.Text = dataReader["address"].ToString();
                            if (comboBox1.SelectedItem.ToString() == dataReader["gender"].ToString())
                            {
                                comboBox1.SelectedItem.ToString() = dataReader["gender"].ToString();
                            }
    
    
                            i++;
                        }
                        connectionString.Close();
                        connectionState = false;
    
                    }
    
                    dataReader.Close();
                    connectionString.Close();
                    connectionState = false;
                }
                catch (Exception ex)
                {
    
                    if (connectionState == true)
                    {
                        connectionString.Close();
                        connectionState = false;
                    }
                    MessageBox.Show(ex.Message);
                }
    
            }
    
    
    
    
    
    
    
    
    
    
            public void DeleteEmployee(int id)
            {
                string sqlQuery = "delete from employee where id=" + id;
    
    
                try
                {
    
                    connectionString.Open();
                    connectionState = true;
    
                    command = new SqlCommand(sqlQuery, connectionString);
                    command.ExecuteNonQuery();
    
                    connectionString.Close();
                    connectionState = false;
    
                }
                catch (Exception ex)
                {
                    if (connectionState == true)
                    {
                        connectionString.Close();
                        connectionState = false;
                    }
    
                    System.Windows.Forms.MessageBox.Show(ex.Message, "Error on remove");
                }
    
    
    
            }

    PS: There's better way of writing code that uses databases, but I think you need something that works for now.

    Please try this first, and if doesn't work. Come here again that I will send you a project very understandable and that will 100% work.
    I didn't catch errors perfectly, but these is just to enlighten you, bro



    BP-LP 2005/2016 @ll rights reserved





    Thursday, January 31, 2019 8:06 AM