Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

CSV ODBC Datasource won't change at runtime

$
0
0

I'm sure that I'm missing something simple here.  Working on a template that reports from a csv file using the microsoft text driver in ODBC.  Running the report using CR Basic for VS2008 (10.5).   The csv filename it was designed with is "supplm.csv", but sometimes at runtime we need to change the file name from "supplm.csv" to "supplm1.csv".  The number may increase as needed if csv files already exist, because another user is running that same report.  I can not get the table.location to change at runtime, it throws me an error.  I have searched and looked at samples, and just don't see what I'm doing different.

 

This is a continuation of our upgrade from CR6.5 to CR2011.  With the old crpe engine, we would set the entire sql statement on the report to change the filename it was running from.  I don't see a way to do that anymore, so I'm trying to change the table name (supplm1.csv) using its alias (supplm_csv).  I have done the same sort of thing before for normal sql tables, but the text file isn't working for me.

 

The main report's query:  (there are subreports that pull more data, this just happens to be first.)

SELECT `supplm_csv`.`LOCID`, `supplm_csv`.`COMMODITY`

FROM   `supplm.csv` `supplm_csv`

ORDER BY `supplm_csv`.`LOCID`, `supplm_csv`.`COMMODITY`

 

ODBC: CRTEXT  (microsoft text driver (*.txt, *.csv))

     I currently have the directory to use set to a specific folder "H:\PETest".

 

My current code:

 

public bool setCSVFileLocation(string sTableName, string sNewFilePath, string sNewFileName)

        {

            bool bOk = true;           

            try

            {

                bool bFound = false;

                foreach (Table tbl in frm.doc.Database.Tables)

                {

                    MessageBox.Show(tbl.Name);

                    if(tbl.Name.Equals(sTableName, StringComparison.CurrentCultureIgnoreCase))

                    {

                        bFound=true;

                        MessageBox.Show("Table found");                       

 

                        ConnectionInfo connInfo = new ConnectionInfo();

                        connInfo.UserID = "";

                        connInfo.Password = "";

                        connInfo.DatabaseName = sNewFilePath;

                        connInfo.ServerName = "CRTEXT";

                        connInfo.Type = ConnectionInfoType.DBFile;                             

                       

                        TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();                                               

                        tableLogOnInfo.ConnectionInfo = connInfo;

                        tableLogOnInfo.TableName = sNewFileName;                       

                        tbl.ApplyLogOnInfo(tableLogOnInfo);

                        MessageBox.Show("log on info applied");

 

                        tbl.Location = sNewFileName;                       

                        MessageBox.Show("Location set");

                    }

                }

                if(!bFound)

                    MessageBox.Show("no matching table found");

 

            }

            catch (Exception e)

            {

                bOk = false;

                MessageBox.Show("An error occurred setting CSV location.\n" +

                            "Table Name: " + frm.doc.Database.Tables[sTableName].LogOnInfo.TableName + "\n" +

                            "Location: " + frm.doc.Database.Tables[sTableName].Location + "\n" +

                            "DB Name: " + frm.doc.Database.Tables[sTableName].LogOnInfo.ConnectionInfo.DatabaseName + "\n" +

                            "CSV File: " + Path.Combine(sNewFilePath, sNewFileName) + "\n" +

                            "Temp File: " + Path.Combine(Path.GetTempPath(), sNewFileName) + "\n" +

                            "new location: " + sNewFileName + "\n" +

                            "\n\n" + e.Message, sMSG_BOX_TITLE,

                           MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

            }           

            return bOk;

        }

 

I get the message box that "log on info applied", but the program throws an exception after that.

 

 

I have tried copying the csv file into the temp folder, but that doesn't help.  Opening the report inside of CR2011 and updating the datasource location, and it runs from the "supplm1.csv" file fine.

 

Hope this is enough information to start with.  Appreciate any help or insight.


Viewing all articles
Browse latest Browse all 3636

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>