I know this isn't a silverlight forum but I didn't see a specific one direct to it so hope this is ok spot.
Just learning silverlight and it seems talking to database is very different than what I am use to. I have researched and researched and I just don't seem to be doing it right.
What I am trying to do is read my forums user tables and match that when they log in my control it will know if they are a registered member or need to register at the forums.
I have done this with exact same database code in desktop application and it works fine but I can't get it done with silverlight.
I know have to do it in wcf which I also have not used before and here is some samples of what I have done to try it out.
In my xaml class.
ServiceReference1.Service1Client logIn = new ServiceReference1.Service1Client();
logIn.SaltReturnCompleted += new EventHandler<SaltReturnCompletedEventArgs> (logIn_SaltReturnCompleted);
logIn.SaltReturnAsync(tBoxUName.Text);
private void logIn_SaltReturnCompleted(object sender, SaltReturnCompletedEventArgs e)
{
//this.salt = (string)e.Result;
tBlockError.Text = (string)e.Result;
tBlockError.Visibility = Visibility.Visible;
}
|
In my web config.
<connectionStrings>
<add name="DBConnectionString" connectionString="Data Source=adress to server withheld for security; Initial Catalog=database name withheld for security;Username=withheld for security;Password=withheld for security"/>
</connectionStrings>
|
My wcf code.
[OperationContract]
public string SaltReturn(string tempUser)
{
string tempSalt = "";
ArrayList salt = new ArrayList();
using (SqlConnection con = new SqlConnection())
{
// Configure the SqlConnection object's connection string.
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
// Open the database connection.
try
{
con.Open();
}//closes try.
catch (Exception)
{
}//closes catch.
if (con.State == ConnectionState.Open)
{
try
{
SqlCommand command = new SqlCommand ("SELECT salt FROM bvtvweb_user WHERE (username = '" + tempUser + "');", con);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
tempSalt = reader.GetString(0);
salt.Add(tempSalt);
}//closes while.
reader.Close();
}//closes try.
catch (Exception)
{
}//closes catch.
if (salt.Contains(tempSalt))
{
}//closes if.
else
{
tempSalt = "";
}//closes else.
}//closes if.
}//closes using.
return tempSalt;
}//closes method.
|
Can someone please clue me in on where I am going wrong?