Link to home
Start Free TrialLog in
Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScFlag for Zambia

asked on

Correct connection string from C# Windows Form App into Ms SQL Server

I'm not able to insert my data from C# Windows Forms Application with the code below, the error message is below as well, please note that my MS SQL Server database name is called CaPremier

System.ArgumentException: 'Keyword not supported: 'initialcatalog ( This is my error message I'm getting)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=SQL EXPRESS;InitialCatalog=CaPremier.mdf;Integrated Security=True;User Instance=True");
            SqlCommand cmd;
            con.Open();
            string s = "insert into SalesTraining values(@customer,@address)";
            cmd = new SqlCommand(s, con);
            cmd.Parameters.AddWithValue("@customer", txtCustomer.Text);
            cmd.Parameters.AddWithValue("@address", txtAddress.Text);
            cmd.CommandType = CommandType.Text;
            int i = cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show(i + " Row(s) Inserted ");
        }
    }
}

Kindly see how you can help

Regards

Chris
Avatar of Russ Suter
Russ Suter

"Initial Catalog" needs to be two words separated by a space.
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial