Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • 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 SotoCommented:
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 SotoCommented:
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 SotoCommented:
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 SotoCommented:
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 SotoCommented:
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 SotoCommented:
Thank you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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