Compare tables between two MDF filesWhat is the difference between String and string in C#?How do I check whether a file exists without exceptions?Add a column with a default value to an existing table in SQL ServerHow do I copy a file in Python?How to check if a column exists in a SQL Server table?How do I include a JavaScript file in another JavaScript file?What is the best way to auto-generate INSERT statements for a SQL Server table?Writing files in Node.jsHow to read a file line-by-line into a list?how to select records from table with all of value of a field
Have GoT's showrunners reacted to the poor reception of the final season?
Have the writers and actors of GOT responded to its poor reception?
How can I monitor the bulk API limit?
Lock out of Oracle based on Windows username
Cryptic crossword (printer's devilry edition)
Failing students when it might cause them economic ruin
Why do academics prefer Mac/Linux?
Shortest amud or daf in Shas?
on the truth quest vs in the quest for truth
Why does the U.S military use mercenaries?
I recently started my machine learning PhD and I have absolutely no idea what I'm doing
Can 2 light bulbs of 120V in series be used on 230V AC?
Why is Drogon so much better in battle than Rhaegal and Viserion?
Gambler's Fallacy Dice
Why is so much ransomware breakable?
Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?
What should I wear to go and sign an employment contract?
Why using a variable as index of a list-item does not retrieve that item with clist_item:Nn?
Is it a good idea to teach algorithm courses using pseudocode?
mirror damper material
Error when running ((x++)) as root
Appropriate liquid/solvent for life in my underground environment on Venus
Can Gate draw a creature larger that 20 feet in every dimension through the portal it creates?
Should all adjustments be random effects in a mixed linear effect?
Compare tables between two MDF files
What is the difference between String and string in C#?How do I check whether a file exists without exceptions?Add a column with a default value to an existing table in SQL ServerHow do I copy a file in Python?How to check if a column exists in a SQL Server table?How do I include a JavaScript file in another JavaScript file?What is the best way to auto-generate INSERT statements for a SQL Server table?Writing files in Node.jsHow to read a file line-by-line into a list?how to select records from table with all of value of a field
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am attempting to synchronizing tables in two different .MDF files. After successfully creating a datatable for the first file I get an error when trying to create the second:
Cannot attach file 'E:JVT-Inventory.mdf' as database 'JVT-Inventory' because this database name is already attached with file 'C:DatabaseJVT-Inventory.mdf'
I have created separate procedures for each connection to create the tables then disposed the connection. Both the datatable and adapter are global variables to be used in my routines to compare the tables. None of the online research seems to apply to what I am trying to accomplish.
string conString;
conString = "Data Source=(LocalDB)\v11.0;attachdbfilename=" + @txtPath.Text + ";Initial Catalog=JVT-Inventory;integrated security=True";
using (SqlConnection connection = new SqlConnection(conString))
{
daRemote = new SqlDataAdapter("SELECT * FROM tblProduct ORDER BY keyPartNo", connection);
SqlCommandBuilder cbRemote = new SqlCommandBuilder(daRemote);
daRemote.Fill(dtRemote);
connection.Dispose();
This connection is made to a file on a flash drive.
The issue appears to be that the MDF file remains open until I exit the application. My question now is, how do I close the MDF file from within my application?
c#
add a comment |
I am attempting to synchronizing tables in two different .MDF files. After successfully creating a datatable for the first file I get an error when trying to create the second:
Cannot attach file 'E:JVT-Inventory.mdf' as database 'JVT-Inventory' because this database name is already attached with file 'C:DatabaseJVT-Inventory.mdf'
I have created separate procedures for each connection to create the tables then disposed the connection. Both the datatable and adapter are global variables to be used in my routines to compare the tables. None of the online research seems to apply to what I am trying to accomplish.
string conString;
conString = "Data Source=(LocalDB)\v11.0;attachdbfilename=" + @txtPath.Text + ";Initial Catalog=JVT-Inventory;integrated security=True";
using (SqlConnection connection = new SqlConnection(conString))
{
daRemote = new SqlDataAdapter("SELECT * FROM tblProduct ORDER BY keyPartNo", connection);
SqlCommandBuilder cbRemote = new SqlCommandBuilder(daRemote);
daRemote.Fill(dtRemote);
connection.Dispose();
This connection is made to a file on a flash drive.
The issue appears to be that the MDF file remains open until I exit the application. My question now is, how do I close the MDF file from within my application?
c#
The error message is self-explaining. DB names on the server must be unique.
– Alex Kudryashev
Mar 23 at 18:11
There is no server. The application attaches to the database file from one location on the hard drive. I want to compare that to another database file on a flash drive. Even after closing and clearing the connection it appears the database remains in memory, therefore creating your "self-explaining" (obvious) duplication.
– Charles
Mar 23 at 18:32
There is SQL Server (LocalDB) to which youattachyour.mdf.
– Alex Kudryashev
Mar 23 at 18:41
Alex, since the (LocalDB) IS a server and I have two separate files, it would stand to reason that I have two separate servers. Therefore, the DB name on each server is unique. The issue I had was one I still don't understand because I disposed the connections but the name remained (somehow) in memory.
– Charles
Mar 26 at 22:55
add a comment |
I am attempting to synchronizing tables in two different .MDF files. After successfully creating a datatable for the first file I get an error when trying to create the second:
Cannot attach file 'E:JVT-Inventory.mdf' as database 'JVT-Inventory' because this database name is already attached with file 'C:DatabaseJVT-Inventory.mdf'
I have created separate procedures for each connection to create the tables then disposed the connection. Both the datatable and adapter are global variables to be used in my routines to compare the tables. None of the online research seems to apply to what I am trying to accomplish.
string conString;
conString = "Data Source=(LocalDB)\v11.0;attachdbfilename=" + @txtPath.Text + ";Initial Catalog=JVT-Inventory;integrated security=True";
using (SqlConnection connection = new SqlConnection(conString))
{
daRemote = new SqlDataAdapter("SELECT * FROM tblProduct ORDER BY keyPartNo", connection);
SqlCommandBuilder cbRemote = new SqlCommandBuilder(daRemote);
daRemote.Fill(dtRemote);
connection.Dispose();
This connection is made to a file on a flash drive.
The issue appears to be that the MDF file remains open until I exit the application. My question now is, how do I close the MDF file from within my application?
c#
I am attempting to synchronizing tables in two different .MDF files. After successfully creating a datatable for the first file I get an error when trying to create the second:
Cannot attach file 'E:JVT-Inventory.mdf' as database 'JVT-Inventory' because this database name is already attached with file 'C:DatabaseJVT-Inventory.mdf'
I have created separate procedures for each connection to create the tables then disposed the connection. Both the datatable and adapter are global variables to be used in my routines to compare the tables. None of the online research seems to apply to what I am trying to accomplish.
string conString;
conString = "Data Source=(LocalDB)\v11.0;attachdbfilename=" + @txtPath.Text + ";Initial Catalog=JVT-Inventory;integrated security=True";
using (SqlConnection connection = new SqlConnection(conString))
{
daRemote = new SqlDataAdapter("SELECT * FROM tblProduct ORDER BY keyPartNo", connection);
SqlCommandBuilder cbRemote = new SqlCommandBuilder(daRemote);
daRemote.Fill(dtRemote);
connection.Dispose();
This connection is made to a file on a flash drive.
The issue appears to be that the MDF file remains open until I exit the application. My question now is, how do I close the MDF file from within my application?
c#
c#
edited Mar 23 at 20:30
Charles
asked Mar 23 at 17:08
CharlesCharles
195
195
The error message is self-explaining. DB names on the server must be unique.
– Alex Kudryashev
Mar 23 at 18:11
There is no server. The application attaches to the database file from one location on the hard drive. I want to compare that to another database file on a flash drive. Even after closing and clearing the connection it appears the database remains in memory, therefore creating your "self-explaining" (obvious) duplication.
– Charles
Mar 23 at 18:32
There is SQL Server (LocalDB) to which youattachyour.mdf.
– Alex Kudryashev
Mar 23 at 18:41
Alex, since the (LocalDB) IS a server and I have two separate files, it would stand to reason that I have two separate servers. Therefore, the DB name on each server is unique. The issue I had was one I still don't understand because I disposed the connections but the name remained (somehow) in memory.
– Charles
Mar 26 at 22:55
add a comment |
The error message is self-explaining. DB names on the server must be unique.
– Alex Kudryashev
Mar 23 at 18:11
There is no server. The application attaches to the database file from one location on the hard drive. I want to compare that to another database file on a flash drive. Even after closing and clearing the connection it appears the database remains in memory, therefore creating your "self-explaining" (obvious) duplication.
– Charles
Mar 23 at 18:32
There is SQL Server (LocalDB) to which youattachyour.mdf.
– Alex Kudryashev
Mar 23 at 18:41
Alex, since the (LocalDB) IS a server and I have two separate files, it would stand to reason that I have two separate servers. Therefore, the DB name on each server is unique. The issue I had was one I still don't understand because I disposed the connections but the name remained (somehow) in memory.
– Charles
Mar 26 at 22:55
The error message is self-explaining. DB names on the server must be unique.
– Alex Kudryashev
Mar 23 at 18:11
The error message is self-explaining. DB names on the server must be unique.
– Alex Kudryashev
Mar 23 at 18:11
There is no server. The application attaches to the database file from one location on the hard drive. I want to compare that to another database file on a flash drive. Even after closing and clearing the connection it appears the database remains in memory, therefore creating your "self-explaining" (obvious) duplication.
– Charles
Mar 23 at 18:32
There is no server. The application attaches to the database file from one location on the hard drive. I want to compare that to another database file on a flash drive. Even after closing and clearing the connection it appears the database remains in memory, therefore creating your "self-explaining" (obvious) duplication.
– Charles
Mar 23 at 18:32
There is SQL Server (LocalDB) to which you
attach your .mdf.– Alex Kudryashev
Mar 23 at 18:41
There is SQL Server (LocalDB) to which you
attach your .mdf.– Alex Kudryashev
Mar 23 at 18:41
Alex, since the (LocalDB) IS a server and I have two separate files, it would stand to reason that I have two separate servers. Therefore, the DB name on each server is unique. The issue I had was one I still don't understand because I disposed the connections but the name remained (somehow) in memory.
– Charles
Mar 26 at 22:55
Alex, since the (LocalDB) IS a server and I have two separate files, it would stand to reason that I have two separate servers. Therefore, the DB name on each server is unique. The issue I had was one I still don't understand because I disposed the connections but the name remained (somehow) in memory.
– Charles
Mar 26 at 22:55
add a comment |
1 Answer
1
active
oldest
votes
After searching many articles about working with databases I figured out the follow:
SqlConnection cnRemoteBye = new SqlConnection();
SqlCommand cmdRemoteBye = new SqlCommand();
cnRemoteBye.ConnectionString = @"Data Source=(LocalDB)v11.0;Integrated Security=True";
cmdRemoteBye.CommandText = "ALTER DATABASE [JVT-Inventory] SET OFFLINE WITH ROLLBACK IMMEDIATE nr exec sp_detach_db @dbname = [JVT-Inventory]";
cmdRemoteBye.Connection = cnRemoteBye;
cnRemoteBye.Open();
cmdRemoteBye.ExecuteNonQuery();
cnRemoteBye.Close();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316281%2fcompare-tables-between-two-mdf-files%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After searching many articles about working with databases I figured out the follow:
SqlConnection cnRemoteBye = new SqlConnection();
SqlCommand cmdRemoteBye = new SqlCommand();
cnRemoteBye.ConnectionString = @"Data Source=(LocalDB)v11.0;Integrated Security=True";
cmdRemoteBye.CommandText = "ALTER DATABASE [JVT-Inventory] SET OFFLINE WITH ROLLBACK IMMEDIATE nr exec sp_detach_db @dbname = [JVT-Inventory]";
cmdRemoteBye.Connection = cnRemoteBye;
cnRemoteBye.Open();
cmdRemoteBye.ExecuteNonQuery();
cnRemoteBye.Close();
add a comment |
After searching many articles about working with databases I figured out the follow:
SqlConnection cnRemoteBye = new SqlConnection();
SqlCommand cmdRemoteBye = new SqlCommand();
cnRemoteBye.ConnectionString = @"Data Source=(LocalDB)v11.0;Integrated Security=True";
cmdRemoteBye.CommandText = "ALTER DATABASE [JVT-Inventory] SET OFFLINE WITH ROLLBACK IMMEDIATE nr exec sp_detach_db @dbname = [JVT-Inventory]";
cmdRemoteBye.Connection = cnRemoteBye;
cnRemoteBye.Open();
cmdRemoteBye.ExecuteNonQuery();
cnRemoteBye.Close();
add a comment |
After searching many articles about working with databases I figured out the follow:
SqlConnection cnRemoteBye = new SqlConnection();
SqlCommand cmdRemoteBye = new SqlCommand();
cnRemoteBye.ConnectionString = @"Data Source=(LocalDB)v11.0;Integrated Security=True";
cmdRemoteBye.CommandText = "ALTER DATABASE [JVT-Inventory] SET OFFLINE WITH ROLLBACK IMMEDIATE nr exec sp_detach_db @dbname = [JVT-Inventory]";
cmdRemoteBye.Connection = cnRemoteBye;
cnRemoteBye.Open();
cmdRemoteBye.ExecuteNonQuery();
cnRemoteBye.Close();
After searching many articles about working with databases I figured out the follow:
SqlConnection cnRemoteBye = new SqlConnection();
SqlCommand cmdRemoteBye = new SqlCommand();
cnRemoteBye.ConnectionString = @"Data Source=(LocalDB)v11.0;Integrated Security=True";
cmdRemoteBye.CommandText = "ALTER DATABASE [JVT-Inventory] SET OFFLINE WITH ROLLBACK IMMEDIATE nr exec sp_detach_db @dbname = [JVT-Inventory]";
cmdRemoteBye.Connection = cnRemoteBye;
cnRemoteBye.Open();
cmdRemoteBye.ExecuteNonQuery();
cnRemoteBye.Close();
answered Mar 24 at 15:26
CharlesCharles
195
195
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316281%2fcompare-tables-between-two-mdf-files%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The error message is self-explaining. DB names on the server must be unique.
– Alex Kudryashev
Mar 23 at 18:11
There is no server. The application attaches to the database file from one location on the hard drive. I want to compare that to another database file on a flash drive. Even after closing and clearing the connection it appears the database remains in memory, therefore creating your "self-explaining" (obvious) duplication.
– Charles
Mar 23 at 18:32
There is SQL Server (LocalDB) to which you
attachyour.mdf.– Alex Kudryashev
Mar 23 at 18:41
Alex, since the (LocalDB) IS a server and I have two separate files, it would stand to reason that I have two separate servers. Therefore, the DB name on each server is unique. The issue I had was one I still don't understand because I disposed the connections but the name remained (somehow) in memory.
– Charles
Mar 26 at 22:55