Data Analytics

Changing Times for Data Professionals.

A good, short post on Data Analytics, and why we need to be paying more attention to them. In the end this is an invitation to the conference, but the post applies to all of us that work with data.

Advertisements

This was a weird issue that a coworker had that I thought I would re-post so others (and I) could find it easily when it comes up again. We were adding a report via the report wizard. Visual Studio (apparently) attempts to load the data sources you may have sitting in your Bin folder. If it cannot load one of those (for some reason), it will fail to bring up the report wizard (where you may be creating a new data source anyway).

ReportWizardError

The solution feels a lot like a hack (but this is Microsoft, right – comes with the territory).

Rename your Bin folder, then run your wizard, then rename it back.

Just wow.

I got this solution from here.

Connecting from Windows 8 to a Windows 7 share

This was driving me crazy. I would try several things that didn’t work, and after checking firewall stuff, and many other things — no luck.

Finally I stumbled on this info at :
http://www.neowin.net/forum/topic/1109019-so-windows-8-and-filesharing-does-it-even-work/

On the Win 8 box navigate to the following:
Control Panel\All Control Panel Items\Network and Sharing Center\Advanced sharing settings

Select ‘Use user accounts and passwords to connect to other computers’.

Then I logged into the PC at the computer name level and said save credentials. Ahh – I can finally update subversion from this laptop again!

Thanks SledgeNZ!

Update!

This broke again a week later. I found that somehow windows 7 had its firewall on at the same time. If you are running Norton 360, apparently in some cases, Windows will keep or turn back on its firewall. You should make sure that at your firewall settings:

WindowsFirewall

after selecting “Advanced Settings”:

WindowsFirewallAdvancedSettingsThat the firewall is turned off like shown above.

Disclaimer: Don’t mess with your firewall settings unless you are confident that you know what you are doing as you can lose data, and have your computer infested with viruses!

I am doing this based on input from Norton and have their firewall installed and active, thus a second firewall is both redundant, and can cause problems where you can’t connect when you should be able to.

The pertinent link is: http://community.norton.com/t5/Norton-Internet-Security-Norton/I-can-t-reach-computers-on-my-VISTA-network/m-p/381470/highlight/true#M144115

LinqPad – Get Pdf from binary column

A friend asked me to share this technique (which rocks!) for a simple way to pull a pdf from a table without writing an application to do it. It has saved me a lot of time when I need to get to a stored pdf quickly.

LinqPad (which if you do any Linq, and in this case even if you just need to get to a binary object) is a must-have program that allows you to do this.

Here is the simple code snippet that pulls the pdf, saves it to a file, and opens it. You have to connect your database on the top right, and select “C# Statements” in the middle drop down list:

string id = "60821 003";
string dir = "C:\\TempDocs";

// create output directory
Directory.CreateDirectory(dir);

// create output filename
string outputPDFFile = Path.Combine(dir, id + ".pdf");

// find the record we want (you have to be connected 
// to the database you want to search, and
// PDFDocuments below must match the table you are pulling data from
var mypdf = (from q2 in PDFDocuments where q2.PrintBatchId == id select q2);

// above returns only one record, so below I use SingleOrDefault to get that record.
// otherwise here you could iterate through the records...
// the ".Pdf portion pf this is the column name of the pdf binary data in the table
File.WriteAllBytes(outputPDFFile, mypdf.SingleOrDefault().Pdf.ToArray());

// this part opens up the pdf for viewing / verifying I have the right one
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = outputPDFFile;
proc.Start();

Have fun!

asp.net GridView BoundField width not working – alternatives

Here is a quick snippet of an issue I ran into. I am not sure where the issue lies with this, but I found that I could not set the ItemStyle-Width=”100px” setting. It would have no effect. In this particular case this was causing the first column of my data to wrap its text.

<asp:GridView ID=”MyGrid” runat=”server” OnRowDataBound=”MyGrid_RowDataBound”

AutoGenerateColumns=”false”>
<Columns>
<asp:BoundField DataField=”Type” HeaderText=”Type” ItemStyle-Wrap=”False” ItemStyle-HorizontalAlign=”Left” />

… more grid stuff here …

The solution I ended up using is posted above. I set ItemStyle-Wrap=”False” and the data pushed out the width of the column. This is a fine solution for this particular time, but there are times when you want to be able to set a specific width. In that case I would use asp:TemplateField instead. The down side of this is that you have to insert your data using Eval().

Peace…

Adapting to the New Normal; tips for managing a virtual company.

Great little article on leveraging the tech of today to form a virtual workplace.

Adapting to the New Normal; tips for managing a virtual company..

 

LINQ to SQL and missing Many to Many EntityRefs – Rick Strahl’s Web Log

Just a quick note: If you are attempting to create a relationship between two tables using a foreign key and use it in Linq to SQL, it is not enough that there is a non-primary key defined in that table. The relationship will show up on the designer but not in the actual code. Linq to SQL requires that there be a primary key defined, even if it is not used in the relationship.

More info at link below:

LINQ to SQL and missing Many to Many EntityRefs – Rick Strahl’s Web Log.

WebMatrix Deployment

I have been noodling with MVC3 / cshtml / Razor, and I put together a web site and tried to deploy it. I was using the WebSecurity that was nicely integrated into the default web site that I started with, and was delighted about how easy it was to implement. With a few hours of work, I had a site that was performing registration, adding users to my database, emailing for confirmation and I didn’t write any of that code! Sweet. Let’s deploy. Then, ugh, an error.

Server Error in ‘/’ Application.


Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The connection name ‘LocalSqlServer’ was not found in the applications configuration or the connection string is empty.

Source Error:

Line 238: <membership> Line 239: <providers> Line 240: <add name=”AspNetSqlMembershipProvider” type=”System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” connectionStringName=”LocalSqlServer” enablePasswordRetrieval=”false” enablePasswordReset=”true” requiresQuestionAndAnswer=”true” applicationName=”/” requiresUniqueEmail=”false” passwordFormat=”Hashed” maxInvalidPasswordAttempts=”5″ minRequiredPasswordLength=”7″ minRequiredNonalphanumericCharacters=”1″ passwordAttemptWindow=”10″ passwordStrengthRegularExpression=”” />  Line 241: <add name=”MySQLMembershipProvider” type=”MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d” connectionStringName=”LocalMySqlServer” enablePasswordRetrieval=”false” enablePasswordReset=”true” requiresQuestionAndAnswer=”true” applicationName=”/” requiresUniqueEmail=”false” passwordFormat=”Clear” maxInvalidPasswordAttempts=”5″ minRequiredPasswordLength=”7″ minRequiredNonalphanumericCharacters=”1″ passwordAttemptWindow=”10″ passwordStrengthRegularExpression=”” /> Line 242: </providers>


Source File: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config    Line: 240


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

I started immediately looking for an entry possibly added by WebMatrix. But there was none referencing AspNetSqlMembershipProvider, or LocalSqlServer. Then I noticed that this reference was in the machine.config of the server. Well, this is not my server, so I contacted support to ask them about it. They promptly and courteously told me that they did not solve programming questions. OK, on my own – no big surprise there. But I thought it might be a normal “gotcha” that lots of people run into. Well, it is… Here is what needs to happen:

First the reference is partially right. You DO need to have this reference in place, however the machine config does not know where your site has put the Membership info. So you have to replace it. Use this:

<connectionStrings>
<clear />
<add name=”myDB” providerName=”System.Data.SqlClient”
connectionString=”Data Source=someserver.com;Initial Catalog=myDB;User ID=myDB_user;Password=’xxxxx’;Integrated Security=False;” />
<remove name=”LocalSqlServer” />
<add name=”LocalSqlServer” providerName=”System.Data.SqlClient”
connectionString=”Data Source=someserver.com;Initial Catalog=myDB;User ID=myDB_user;Password=’xxxxx’;Integrated Security=False;” />
</connectionStrings>

Of course replace the database details with your own.

Once this was in place, I ran it again and got the following error:

Server Error in ‘/’ Application.


The Role Manager feature has not been enabled.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Configuration.Provider.ProviderException: The Role Manager feature has not been enabled.

Source Error:

Line 3: var providerName = “System.Data.SqlClient”; Line 4: //var db = Database.OpenConnectionString(connectionString, providerName); Line 5: WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection (connectionString, providerName, Line 6: “UserProfile”, “UserId”, “Email”, true); Line 7:


Source File: e:\web\myWeb\_AppStart.cshtml    Line: 

It is now looking at my (mind you WORKING LOCALLY 🙂 ) init and saying it is failing. To be honest, since this is new tech for me, I wasn’t sure if I should be enabling the role manager, or if I had enabled something that was adding a new / different security setting that would cause some conflict. With a bit more research (Googling WebSecurity and Role Manager), I saw that the WebSecurity uses the Role Manager in “SimpleMembership” mode. OK, so this is needed and probably ok.

But I don’t need the AspNetSqlMembershipProvider… So I removed it (with the <clear/> below):

Inside the System.Web section of my web.config:

<membership defaultProvider=”SimpleMembershipProvider”>
<providers >
<clear/>
<add name=”SimpleMembershipProvider” type=”WebMatrix.WebData.SimpleMembershipProvider,WebMatrix.WebData”/>
</providers>
</membership>

Then I got the error:

Server Error in ‘/’ Application.


Default Membership Provider must be specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Configuration.Provider.ProviderException: Default Membership Provider must be specified.

With a little more digging, I found that this entry in the appSettings section will take care of that issue.

<add key=”enableSimpleMembership” value=”true” />

I hope this helps someone make a few less round trips searching!

Peace…

Helpful Links for this issue:

http://stackoverflow.com/questions/3874279/the-role-manager-feature-has-not-been-enabled

http://forums.asp.net/t/1695156.aspx/1?WebSecurity+in+MVC

https://forums.iis.net/p/1188577/2018786.aspx

This Is The Secret To Being Truly Successful

Loved this!

… The harder challenge is to do what is hard and fair and noble even when you don’t feel like it at all, when you are “sick and tired” and tired and sick.

Every day matters. Every minute matters.

There are no sick days. So get that out of your head, grab your sword, and start swinging.

via This Is The Secret To Being Truly Successful.

Windows Service testing

This is a handy way to test your windows service; something I have been doing for awhile. I was looking at it recently, and thought it might be handy for someone else:

public static class Program
{
///
/// The main entry point for the application. /// 

public static void Main()
{
#if (!DEBUG)
  ServiceBase[] ServicesToRun;
  ServicesToRun = new ServiceBase[] { new MyWinService() };
  ServiceBase.Run(ServicesToRun);
#else
  //Debug code: this allows the process to run 
  // as a non-service. It will kick off the
  // service start point, and then run the 
  // sleep loop below.
  MyWinService service = new MyWinService();
  service.Start();
  // Break execution and set done to true to run Stop()
  bool done = false;
  while (!done)
   Thread.Sleep(10000);
  service.Stop();
#endif
}

By using this approach, you can compile a release version of the service that runs like a service, and while debugging, you can run the loop in the debug section that allows you to break and set done and fully test your startup and shutdown code.

HTH,

Robb