c# how to insert and update dater-base

  • Thread starter Thread starter elfenliedtopfan55
  • Start date Start date
E

elfenliedtopfan55

Guest
ok so i have the following code

string connString;
connString = $"SERVER={server};DATABASE={database};UID={uid};PASSWORD={password};";
string test = processorid + mbored;

SqlConnection Con = new SqlConnection(connString);

SqlCommand Cmd = new SqlCommand("INSERT INTO elfenliedtopfan5_login " +
"(machineid) " +
"VALUES(@machineid)",
Con);


Cmd.Parameters.Add("@machineid", System.Data.SqlDbType.Int);


Cmd.Parameters["@machineid"].Value = test;

Con.Open();

int RowsAffected = Cmd.ExecuteNonQuery();

Con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

}


but i get the following error when trying to insert data into the database

{"A network-related or instance-specific error occurred while establishing a connection 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}


not quite sure what this is happening as checked the connection string and this connects fine but for some reason i cant seem to get it to update any data or add data to it.

Continue reading...
 
Back
Top