fout in script

Status
Niet open voor verdere reacties.

jolanda05031975

Gebruiker
Lid geworden
7 feb 2014
Berichten
31
In onderstaande script zit ergens een fout, ik zie alleen niet waar. Kan iemand mij helpen

String ErrInfo = "";
String FilePath = Dts.Variables["User::varFilePath"].Value.ToString();
try
{
String FileContent; //Variable to store File Contents
FileContent = ReadFile(FilePath, ErrInfo);
Regel 105 if (ErrInfo.Length > 0)
{
Dts.Log("Error while reading File " + FilePath, 0, null);
Dts.Log(ErrInfo, 0, null);
Dts.TaskResult = (int)ScriptResults.Failure;
return;
}


FileContent = FileContent.Replace("<", "<"); FileContent = FileContent.Replace(">", ">");
FileContent = FileContent.Replace("&", "&");
FileContent = FileContent.Replace("encoding="utf-16"", string.Empty);

FileContent = FileContent.Replace("<string>",string.Empty);
FileContent = FileContent.Replace("</string>", string.Empty);


WriteToFile(FilePath, FileContent, ErrInfo);
if (ErrInfo.Length > 0)
{
Dts.Log("Error while writing File " + FilePath, 0, null);
Dts.Log(ErrInfo, 0, null);
Dts.TaskResult = (int)ScriptResults.Failure;
return;
}
}
catch (Exception e)
{
Dts.Log(e.Message, 0, null);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}

public String ReadFile(String FilePath, String ErrInfo)
{
String strContents;
StreamReader sReader;
try
{
sReader = File.OpenText(FilePath);
strContents = sReader.ReadToEnd();
sReader.Close();
return strContents;
}
catch (Exception e)
{
MessageBox.Show(ErrInfo);
ErrInfo = e.Message;
return "";
}
}

public void WriteToFile(String FilePath, String strContents, String ErrInfo)
{
StreamWriter sWriter;
try
{
sWriter = new StreamWriter(FilePath);
sWriter.Write(strContents);
sWriter.Close();
}
catch (Exception e)
{
MessageBox.Show(ErrInfo);
ErrInfo = e.Message;
}
}
 
Laatst bewerkt:
Ik neem aan dat je een foutmelding krijgt? Zoja, welke is dat dan? En is dat een complier of runtime melding?
Gaat dit programma draaien op een Mac of op een Windows machine?
 
Laatst bewerkt:
Windows Machine
Script Task Editor in SQL Server Data Tools (Visual Studio 2015)

Regel 105 is if (ErrInfo.Length & gt; 0)
Regel 118 is FileContent = FileContent.Replace("encoding="utf - 16"", string.Empty);
Regel 125 is if (ErrInfo.Length & gt; 0)

Severity Code Description Project File Line Suppression State
Error CS1026 ) expected ST_36c4a417b9134512baaf50cd37b1de6d C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaY__JMFvnlu0__gwNX_KLmtTw\Vsta6AK9Zaxr90yxGpj9GWpSdQ\ScriptMain.cs 105 Active
Error CS1002 ; expected ST_36c4a417b9134512baaf50cd37b1de6d C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaY__JMFvnlu0__gwNX_KLmtTw\Vsta6AK9Zaxr90yxGpj9GWpSdQ\ScriptMain.cs 105 Active
Error CS1513 } expected ST_36c4a417b9134512baaf50cd37b1de6d C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaY__JMFvnlu0__gwNX_KLmtTw\Vsta6AK9Zaxr90yxGpj9GWpSdQ\ScriptMain.cs 105 Active
Error CS1003 Syntax error, ',' expected ST_36c4a417b9134512baaf50cd37b1de6d C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaY__JMFvnlu0__gwNX_KLmtTw\Vsta6AK9Zaxr90yxGpj9GWpSdQ\ScriptMain.cs 118 Active
Error CS1003 Syntax error, ',' expected ST_36c4a417b9134512baaf50cd37b1de6d C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaY__JMFvnlu0__gwNX_KLmtTw\Vsta6AK9Zaxr90yxGpj9GWpSdQ\ScriptMain.cs 118 Active
Error CS1026 ) expected ST_36c4a417b9134512baaf50cd37b1de6d C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaY__JMFvnlu0__gwNX_KLmtTw\Vsta6AK9Zaxr90yxGpj9GWpSdQ\ScriptMain.cs 125 Active
Error CS1002 ; expected ST_36c4a417b9134512baaf50cd37b1de6d C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaY__JMFvnlu0__gwNX_KLmtTw\Vsta6AK9Zaxr90yxGpj9GWpSdQ\ScriptMain.cs 125 Active
Error CS1513 } expected ST_36c4a417b9134512baaf50cd37b1de6d C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaY__JMFvnlu0__gwNX_KLmtTw\Vsta6AK9Zaxr90yxGpj9GWpSdQ\ScriptMain.cs 125 Active
 
IK gebruik die taal nooit maar ik vind dit erg vreemd:
if (ErrInfo.Length > 0)

Die > is de HTML variant van een groter dan teken.
Verander dat dus eens in dit:
if (ErrInfo.Length > 0)
 
Dit was inderdaad de oplossing voor de 2 fouten.

Nu heb ik alleen nog deze fout

FileContent = FileContent.Replace("encoding="utf - 16"", string.Empty);

Het gaat fout bij de "" volgens mij
 
Dat denk ik ook. Maak er eens dit van:
FileContent = FileContent.Replace("encoding=""utf - 16""", string.Empty);
 
Helaas dezelfde foutmelding

Severity Code Description Project File Line Suppression State
Error CS1003 Syntax error, ',' expected ST_fff949125692435f8982f77cce65eb18 C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaaccuAqq6pE__MrEjD7__6vLg\Vstao__rhglcz4EqWyaknmZmahg\ScriptMain.cs 113 Active
Error CS1003 Syntax error, ',' expected ST_fff949125692435f8982f77cce65eb18 C:\Users\Dennis prive\AppData\Local\Temp\Vsta\SSIS_ST130\VstaaccuAqq6pE__MrEjD7__6vLg\Vstao__rhglcz4EqWyaknmZmahg\ScriptMain.cs 113 Active
 
Dan zal je moeten kijken hoe je in die taal met die quotes moet omgaan. Je zoekt naar dit:
encoding="utf - 16"

Zoek dus uit hoe je die quotes moet "escapen".
 
Gevonden. Het moest dit zijn

FileContent = FileContent.Replace("encoding=utf - 16", string.Empty);

Bedankt voor het mij denken dan kan ik weer even verder.
 
Ok dan. Samen zijn we sterk :p
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan