Results 1 to 3 of 3

Thread: c# Save button SQL connection fail

  1. #1

    Joined
    Dec 2014
    Posts
    76
    Userbars
    1
    Thanks
    27
    Thanked
    10/9
    DL/UL
    59/0
    Mentioned
    17 times
    Time Online
    4d 8h 1m
    Avg. Time Online
    1m

    c# Save button SQL connection fail

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Configuration;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form3 : Form
        {
            public Form3()
            {
                InitializeComponent();
            }
            SqlConnection ABC = new SqlConnection(@"Data Source=C:\Users\Somline\Documents\Visual Studio 2008\Projects\PROGRAMA\WindowsFormsApplication1\Database1.sdf;Persist Security Info=True");
            SqlCommand command = new SqlCommand();
            SqlDataReader dataRead;
    
            private void eMPRESASBindingNavigatorSaveItem_Click(object sender, EventArgs e)
            {
                this.Validate();
                this.eMPRESASBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.cONTATOS);
    
            }
    
            private void Form3_Load(object sender, EventArgs e)
            {
                command.Connection = ABC;
                this.eMPRESASTableAdapter.Fill(this.cONTATOS.EMPRESAS);
            
    
    
            }
    
            private void tELEFONELabel_Click(object sender, EventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                ABC.Open();
               command.CommandText="insert into EMPRESAS(NOME EMPRESA,TELEFONE,ENDERE�O,BAIRRO,CONTATOS) Values('"+nOME_EMPRESATextBox.Text+"','"+tELEFONETextBox.Text+"','"+eNDERE�OTextBox.Text+"','"+bAIRROTextBox.Text+"','"+cONTATOSTextBox.Text+"')";
                command.ExecuteNonQuery();
                ABC.Close();    
                MessageBox.Show("EMPRESA CADASTRADA COM SUCESSO...!");
                nOME_EMPRESATextBox.Clear();
                tELEFONETextBox.Clear();
                eNDERE�OTextBox.Clear();
                bAIRROTextBox.Clear();
                cONTATOSTextBox.Clear();
    
            }
    
            private void eMPRESASDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
    
            }
    
            private void bAIRROLabel_Click(object sender, EventArgs e)
            {
    
            }
    
            private void eMPRESASBindingNavigator_RefreshItems(object sender, EventArgs e)
            {
    
            }
        }
    }

    Appears
    Network error or specific to the instance when connecting to SQL Server . The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. ( Provider: SQL Network Interfaces , error : 26 - Error Locating Server / Instance Specified )
    and
    Warning 1 The field 'WindowsFormsApplication1.Form1.dataRead' is never used C:\Users\Somline\Documents\Visual Studio 2008\Projects\PROGRAMA\WindowsFormsApplication1\Fo rm1.cs 21 23 WindowsFormsApplication1
    (you need an account to see links)
    Code:
    database string : Data Source=C:\Users\Somline\Documents\Visual Studio 2008\Projects\PROGRAMA\WindowsFormsApplication1\Database1.sdf;Persist Security Info=True
    A PROGRAM A LITLE SO LIKE THIS
    HTML Code:
    https://www.youtube.com/watch?v=GysB6QEc04Y
    for run only in my PC thanks
    Last edited by jonatas121; 04-27-2016 at 10:05 AM. Reason: need more info

  2. #2
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,722
    Userbars
    166
    Thanks
    5,907
    Thanked
    33,078/6,609
    DL/UL
    23/36
    Mentioned
    3,867 times
    Time Online
    563d 5h 38m
    Avg. Time Online
    3h 13m
    Based on the error, your app is not connecting to the database.

    Also, you can ignore warnings. And please be more clear?

    You also are using VS 2008... There's 2010, 2013 and 2015... You should consider upgrading.



    Sent from my iPhone using Tapatalk
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  3. #3

    Joined
    Dec 2014
    Posts
    76
    Userbars
    1
    Thanks
    27
    Thanked
    10/9
    DL/UL
    59/0
    Mentioned
    17 times
    Time Online
    4d 8h 1m
    Avg. Time Online
    1m
    I want save a textbox to database, so i use sql connection, but i don't know how to conect with localhost server
    private void button1_Click(object sender, EventArgs e)
    {
    ABC.Open();
    appears
    Network error or specific to the instance when connecting to SQL Server . The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. ( Provider: SQL Network Interfaces , error : 26 - Error Locating Server / Instance Specified )
    Last edited by jonatas121; 04-27-2016 at 12:01 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •