none
client code to access remote sql server RRS feed

  • Question

  • i am using SQL Express CRemote server,i have done the initial steps

    please provide me how to insert data into a remote sql database 

    This Error Appears: Format of the initialization string does not conform to specification starting at index 0.

    and my code to connect remote sql is

     Try
                con = New SqlClient.SqlConnection(" Data Source=192.168.1.3;1433;Network Library=DBMSSOCN;Integrated Security=True;database=e2e")
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

    Try
                con.ConnectionString = ("insert into Contribution values (" & TextBox56.Text & "," & TextBox57.Text & "," & TextBox58.Text & "," & TextBox59.Text & "," & TextBox62.Text & "," & TextBox63.Text & "," & TextBox64.Text & "," & TextBox65.Text & ")")
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            con.Close()

    please help me friends


    Saturday, February 8, 2014 10:24 AM

Answers

  • Hello,

    >>con.ConnectionString

    This propertyis used to get or set the string used to open a SQL Server database. We should use SqlCommandto write the SQL command.

    >>please provide me how to insert data into a remote sql database

    It seems that you are using ADO.NETto insert data to a remote SQLServer Database, then you can follow below steps:

    1.Write the connection string,

    2.Open the connection,

    3.Write the SQL command.

    4.E.xecute the SQL command.

    5.Close the connection.

    For an exact example:

    using System;
    
    using System.Collections.Generic;
    
    using System.Data;
    
    using System.Data.SqlClient;
    
    using System.Linq;
    
    using System.Text;
    
    
    
    namespace P201401
    
    {
    
        class TestForInsertDataInto
    
        {
    
            internal void Execute()
    
            {
    
                string connectionString = @"Data Source=(localdb)\v11.0;Initial Catalog=master;Integrated Security=True";
    
    
    
                SqlConnection connection = new SqlConnection(connectionString);
    
    
    
                try
    
                {
    
                    connection.Open();
    
    
    
                    SqlCommand cmd = new SqlCommand("write your insert command here.", connection);
    
    
    
                    cmd.ExecuteNonQuery();
    
    
    
                    Console.WriteLine("Connect Success!");
    
                }
    
                catch (Exception ex)
    
                {
    
                    Console.WriteLine(ex.Message);
    
                }
    
                finally
    
                {
    
                    connection.Close();
    
                }
    
                Console.ReadLine();
    
    
    
            }
    
        }
    
    }
    

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 10, 2014 2:22 AM
    Moderator