Solved

how to make link data structures rebuild

Posted on 2011-03-20
11
360 Views
Last Modified: 2013-12-17
In Visual Studio 2010 using C#, when I used linkdatasource objects, it created some automatically generated files in App_Code ( .dbml files).

Now I'm returning to an old project, and the designs of the tables in the database have changed. I'm getting errors because the automatically generated linkdatasource info is not matching the database.

How do I make the object refresh itself from the database (rather than continuing to use its old models)?

Sorry I don't know the right names for these objects. Feel free to introduce the topic a little if you understand the concepts.
0
Comment
Question by:JeReLo
  • 6
  • 5
11 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 35175470
Hi JeReLo;

There is no automatic refresh to update the model. What you need to do is to open the DBML file in the designer. Then in Server Explorer right click on the database that contains the tables that have changed, and select the Refresh item from the context menu. View the tables that have changed to make sure that the new columns are now displayed. Now delete the tables that changed in the designer and then select and drag the tables back from Server Explorer. Now the model has been updated.

Fernando
0
 

Author Comment

by:JeReLo
ID: 35177538
Great answer Fernando, I was able to do it.
May I ask a related followup question?

I am setting the connection string in the web.config fie and I'd like the designer to use that connectionstring, but it insists on using it's own. For example, my connection string uses tcp but the designer will use namedpipes when I use the server explorer.

How can I get designer to use my connection string? I tried just editting it, but then the designer complains "The connection property in the web.config file is missing or incorrect. The connection string from the .dbml file has been used in its place."

It then edits my config file (adding the 1 as below):
  <add name="pathsConnection" connectionString="Type System Version=Latest; Network Library=DBMSSOCN; Connect Timeout=5; server=x.x.x.x;  Initial Catalog=paths;  User ID=x; Password=x"
    providerName="System.Data.SqlClient" />
  <add name="pathsConnectionString1" connectionString="Data Source=CORE;Initial Catalog=paths;User ID=x"
    providerName="System.Data.SqlClient" />

Is this normal? Is it preventable?
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 35177598
Hi JeReLo;

You can read the connection string from the web.config file into a string variable and then when you instantiate the data context pass it in as a parameter.

String conStr = // command that reads the connection string from web.config;
DataContextClass db = new DataContextClass( conStr );

Sorry I am not by my computer right now and I am using a mobile device so if you need help getting the connection string from the web.config file into your program I will be able to that when I get back tonight. So let me know if you need that.

Fernando
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:JeReLo
ID: 35178460
That would be great if you could send the code to read in a specified connection string from web.config.

I don't know if this will confuse things or help to clarify the context, but I use a seperate file for connection settings, via this line in web.config

  <connectionStrings configSource="host\HNPS.config"/>

So the connection string is stored in "host\HNPS.config"
and its given a name like this  <add name="pathsConnection" connectionString= etc.

thanks.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 35182294
Hi JeReLo;

Here you go.

// This gets the connection string from the web.config file. 
// The syatem will merge the host\HNPS.config with web.config so access is the
// same with or without the extra file.
ConnectionStringSettings myConn = ConfigurationManager.ConnectionStrings[ "pathsConnection" ];
// Now pass the connection string to the DataContext as a parameter and thats it.
DataClasses1DataContext db = new DataClasses1DataContext( myConn.ConnectionString );

Open in new window


Fernando
0
 

Author Comment

by:JeReLo
ID: 35187677
Thanks for the code Fernando. As is often the case in learning, I found it hard to ask the question to solve the problem I had. The question you answered however, was enough to move me towards solving the problem.

I found the line I needed to edit in the related designer.cs page. When I used my preferred connectionstring name there, then the designer loaded fine.


	public pagevisitsDataContext() :base(global::System.Configuration.ConfigurationManager.ConnectionStrings["pathsConnection"].ConnectionString, mappingSource)

Open in new window


All's well!
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 35189514
Hi JeReLo;

Glad to hear that all is well. Can you please close the question.

Thank you;
Fernando
0
 

Author Comment

by:JeReLo
ID: 35196929
I'm terribly sorry, but I've scanned up and down this page, and the interface is not providing sufficient indication of where I could close the question.

Would you mind giving some indication of where to close it? Can you also confirm you got the points?
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 35199121
Hi JeReLo;

It is not a problem. Log in to your EE account and then come to this page, you will most likely be logged in already. Then go to the comment which best answered your question and in that comment box there should be a button or link that states Accept as Answer or somthing to that effect. That should bring you to a question about assigning points. Once points have been assign the question will be closed.

Fernando
0
 

Author Comment

by:JeReLo
ID: 35202336
thanks, done.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 35202831
Thank you.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question