I have a mdf database file that I am using in my project with ADO.NET Entity Data Model.
It is possible in Server Explorer to get a script file of the database by pressing:
Data Connections => Tabels => [My table Name]Images =>Show Table Data => Script to file
This will get a script that will insert data into the database. What I what to achieve is a script (That I can add to git) that will create the database and insert all data.
Question (Just to be clear): How do I in code generate the script that built my database and inserts data? Example :
GetTheScriptFromMDFDataBase() =>
“CREATE TABLE [dbo].[Image] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[ImageFileName] NVARCHAR (MAX) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
SET IDENTITY_INSERT [dbo].[Image] ON
INSERT INTO [dbo].[Image] ([Id], [ImageFileName]) VALUES (6337, N'L:\Database of fundus images\Not fundus images\epicam not fundus\2017-03-02_10-42-40_video_000000405.jpeg')
INSERT INTO [dbo].[Image] ([Id], [ImageFileName]) VALUES (6338, N'L:\Database of fundus images\Not fundus images\epicam not fundus\2017-03-02_10-42-40_video_000000406.jpeg')
INSERT INTO [dbo].[Image] ([Id], [ImageFileName]) VALUES (6339, N'L:\Database of fundus images\Not fundus images\epicam not fundus\2017-03-02_10-42-40_video_000000407.jpeg')
INSERT INTO [dbo].[Image] ([Id], [ImageFileName]) VALUES (6340, N'L:\Database of fundus images\Not fundus images\epicam not fundus\2017-03-02_10-42-40_video_000000408.jpeg')
INSERT INTO [dbo].[Image] ([Id], [ImageFileName]) VALUES (6341, N'L:\Database of fundus images\Not fundus images\epicam not fundus\2017-03-02_10-42-40_video_000000409.jpeg')
SET IDENTITY_INSERT [dbo].[Image] OFF
I have been looking at SQL Server Management Objects (SMO) But not being able to get it to work.
You can get the script into your code as under:
In your code write
string s = YourProject.Properties.Resources.DbScript;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.