• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

how to make link data structures rebuild

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
JeReLo
Asked:
JeReLo
  • 6
  • 5
1 Solution
 
Fernando SotoRetiredCommented:
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
 
JeReLoAuthor Commented:
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
 
Fernando SotoRetiredCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
JeReLoAuthor Commented:
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
 
Fernando SotoRetiredCommented:
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
 
JeReLoAuthor Commented:
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
 
Fernando SotoRetiredCommented:
Hi JeReLo;

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

Thank you;
Fernando
0
 
JeReLoAuthor Commented:
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
 
Fernando SotoRetiredCommented:
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
 
JeReLoAuthor Commented:
thanks, done.
0
 
Fernando SotoRetiredCommented:
Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now