I have to send my C# Windows Forms project (using SQL Server LocalDB on vs server explorer) to my teacher but if I send her my project with localDB as my database, it doesn't work on her system. What should I do? I really appreciate it if someone helps me.
Asked
Active
Viewed 698 times
-1
-
1I suggest dropping SQL Server and using SQLite instead as it uses a file to store the DB data. For this to work on a different machine, the localDb would have to be set up there too, which is probably not something you can do. – Denis Akopyan Jan 01 '22 at 17:02
-
1*Why* isn't it working on her system? Is it because she doesn't have SQL Server or is that a specific error that she is receiving? – RBarryYoung Jan 01 '22 at 18:00
-
"It doesn't work" is not a proper error description, please be clear – Charlieface Jan 01 '22 at 18:38
-
she doesn't get any errors,I mean cause she doesn't have my database which I created locally,the project doesn't work – sepide naderi Jan 02 '22 at 05:30
2 Answers
1
You can send your database script to your teacher. You can do for Microsoft Sql Server like that:
Right click on your db > Tasks > Generate Scripts... > next > next > Advanced > You should change "Types of data to script" area as "Schema and data". > Click "Open in new query window" radio button. > next > next > finish.
After this process, you can save this script file and send to your teacher.

fatih
- 149
- 1
- 1
- 12
-
thanks for your helping! I really appreciate it. And I have to mention other thing, I created my database in microsoft visual studio,in server explorer part,here can I do what you said ? – sepide naderi Jan 01 '22 at 17:17
-
This process what i wrote can work on Microsoft SQL Server Management Studio. I don't know a method for vs server explorer. – fatih Jan 01 '22 at 17:33
0
I have experienced the same scenario. I just did in this manner,
- Create a database on SQL Server Management Studio and add all the tables and funcs to it
- Just copy and paste the created database from C:\Program Files\Microsoft SQL Server\MSSQLSERVER\MSSQL\DATA\YourDatabase.mdf and YourDatabase_Log.ldf files to your debug folder.
- Lastly, Change your SQLConnection String to connect the database on the location of the
CurrentFolder
which of format,
Connection String
string path = Path.GetFullPath(Environment.CurrentDirectory);
string databaseName = "YourDatabaseName.mdf";
string fullpath = path + @"\" + databaseName;
if (File.Exists(fullpath))
{
SqlConnection con = new SqlConnection(@"Data
Source(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + path + @"\" + databaseName +
"");
return con;
}
else
{
throw new Exception("Database Not Found :(");
}

Opus Corpus
- 115
- 1
- 8