It does not appear that you are setting the 'attribute2' variable in your first code sample. It appears that you should be using 'attribute' instead.
That is just an type. Corrected it.
I tried to reproduce your problem with the following code:
PISystems afServers = new PISystems();
PISystem sys = afServers["dlwin2k8r2x64"];
AFDatabase afDB = sys.Databases["Database3"];
AFElement elem = afDB.Elements["Element1"];
AFAttribute att = elem.Attributes.Add("TableLookupAttribute6");
att.DataReferencePlugIn = sys.DataReferencePlugIns["Table Lookup"];
att.DataReference.ConfigString = "SELECT ColumnName1 FROM Table1 WHERE ColumnName1 = '1'";
However, everything seems to work as expected. What is the AF SDK version? What is the Table Lookup plugin version? Can you try my code and see if you have same problem?