Hi @Dineshkumar.S , Welcome to Microsoft Q&A,
By all users, do you mean all users on your local development machine, or do you mean all users who use your application after release.
If it's the latter, if you want to create a database you need to make sure they have the same database as you.
If ensure that the data being stored does not contain sensitive information, or is properly encrypted when stored.
I suggest you have the option to use XML for inclusion within the app. (Also you can choose to use the embedded database SQLite, embedded in the application.)
Most applications these days choose to use a network database so you don't need to install it on every machine.
If you ensure that all users have SQL databases, you can choose to use Windows Integrated Authentication to create a table in the local database for all users.
Need to ensure Windows Authentication: Make sure your SQL Server database is configured to allow Windows Authentication.
Use localhost and Integrated Security=true.
Write a SQL script: Write a SQL script that contains the statements to create the table.
CREATE TABLE IF NOT EXISTS YourTableName (
ID INT PRIMARY KEY,
Column1 VARCHAR(50),
Column2INT
--Add additional columns and constraints
);
Execute the script when your application starts: Use SqlConnection to execute the above SQL script when your application starts. Before executing, make sure the database already exists, otherwise you can add steps to create the database.
string connectionString = "Data Source=localhost;Initial Catalog=YourDatabaseName;Integrated Security=true;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(yourSqlScript, connection))
{
command.ExecuteNonQuery();
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.