0

I have my application written in C#, it uses a SQL Server database. I have a connection to a database in my C# code, some queries to write/read from database.

Now consider following: if I want to run this app from another PC, this PC has no SQL Server, will this app work? (I assume not) If not then how can this another PC still work with database? Is there a way to programmatically create database on another PC using C# so it has a name I need, columns I need. I created my database using SQL Server Management Studio.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Could you please share your connection string? – Anoop H.N Mar 31 '17 at 03:12
  • You can either back-up and then restore the database, or 'script the database out' (using the tools in SSMS) to avoid re-creating it from scratch if you didn't save the scripts... – Milney Mar 31 '17 at 07:39

2 Answers2

0

I guess your application works with a local server. First of all you should check in your application at startup if there is any local mssql server running. If not, you should handle it by installing one programmatically.

Read this answer how to do this if you don't know it.

After that you have to create the database, it's tables, maybe adding user priviliges. Write a SQL script that gets started by a class that starts it.

Read this to see how to start a SQL script in C#

Community
  • 1
  • 1
Archimedes
  • 231
  • 1
  • 2
  • 13
0

You can do this by setting up SQL server on another machine (server).

Set that servers authentication to SQL Server authentication (requires username and password for that SQL server Management Studio)

Change the connection string in web/App.config from your C# app to use that servers Ip address and Credentails for SQL server

Frankenstine Joe
  • 311
  • 5
  • 14