Thursday, 22 August 2013

Unable to read text file used in CLR function when deployed to SQL SERVER 2008?

Unable to read text file used in CLR function when deployed to SQL SERVER
2008?

I created a CLR User defined function in C# for DID you mean
implementation on my website and deployed the dll in SQL SERVER 2008.
But the dictionary after reading the text file is comming blank.
Below is some part of the code but the problem is in reading text file
string fileContent = File.ReadAllText("big.txt"); List wordList =
fileContent.Split('\n').ToList();
foreach (var word in wordList)
{
string trimmedWord = word.Trim().ToLower();
if (_wordRegex.IsMatch(trimmedWord))
{**strong text**
if (_dictionary.ContainsKey(trimmedWord))
_dictionary[trimmedWord]++;
else
_dictionary.Add(trimmedWord, 1);
}
} public Spelling()
{
try
{
string fileContent = File.ReadAllText("C:/Bgtext/big.txt");
List<string> wordList = fileContent.Split('\n').ToList();
foreach (var word in wordList)
{
string trimmedWord = word.Trim().ToLower();
if (_wordRegex.IsMatch(trimmedWord))
{
if (_dictionary.ContainsKey(trimmedWord))
_dictionary[trimmedWord]++;
else
_dictionary.Add(trimmedWord, 1);
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
[SqlFunction(Name = "CorrectWords", DataAccess = DataAccessKind.Read)]
public static string correctwords(string words)
{
string[] arr = words.Split(' ');
for (int i = 0; i <= arr.Length - 1; i++)
{
arr[i] = Correct(arr[i]);
}
StringBuilder correctedwords = new StringBuilder();
foreach (string value in arr)
{
correctedwords.Append(value);
correctedwords.Append(' ');
}
return correctedwords.ToString();
}
is there any particular location where i need to put my big.txt file after
deploying the dll to sql server or is it a permission issue or is it some
other way to read the text file
Please help as it is urgent

No comments:

Post a Comment