DNN Module compiler error: CS - c#

I am using Module Creator templates for Dotnetnuke 7 trying to make our staff sign in-out module function. Am working with code developed by a volunteer intern from France years ago for DNN 5 Beta. (Some of the spelling is French) I am not a coder myself so am struggling to make the code work in DNN 7. I've managed to figure out a lot of the compiling errors by reading this web site. Thank you. This one has me absolutely stumped:
Error: France is currently unavailable.
DotNetNuke.Services.Exceptions.ModuleLoadException:
d:\HostingSpaces\tgpintra\tgpintranet.org\wwwroot\DesktopModules\TGP\France\View.ascx.cs(176): error CS1010: Newline in constant --->
The source code starting at line 175 is below:
//Set the parameters for updating user's information
SqlUpdate.UpdateCommand = "UPDATE Scotland SET
statut=#statut, timereturn=#timereturn, date=#date, comment=#comment
WHERE name='" +
DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo().Username +
"'";
SqlUpdate.UpdateParameters.Add("statut",
DropDownList2.SelectedValue);
SqlUpdate.UpdateParameters.Add("timereturn",
timereturn.Text);
SqlUpdate.UpdateParameters.Add("date", DateTime.Now.AddHours
(-2).ToString());
SqlUpdate.UpdateParameters.Add("comment", comment.Text);
SqlUpdate.Update();
//Insert a log for the user and his/her new status
SqlConnection MaSqlCnx = new SqlConnection();
MaSqlCnx.ConnectionString = "Server=someserver.
net;Initial Catalog=tgpintra_db;User
Id=theusername;Password=thepassword;";
MaSqlCnx.Open();
SqlCommand MaSqlCmd = new SqlCommand();
MaSqlCmd.Connection = MaSqlCnx;
MaSqlCmd.CommandText = "Insert into ScotlandSchedule(name,
status, time) Values('" +
DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo().FullName +
"', '" + DropDownList2.SelectedValue + "', '" + DateTime.Now.AddHours(-
2).ToString() + "');";
MaSqlCmd.ExecuteNonQuery();
MaSqlCnx.Close();
//Reload the page to update data
Response.AppendHeader("Refresh", "1");
}

Remove the line breaks in the assignment to SqlUpdate.UpdateCommand. You can only have it on one line.

There are two places that will cause this error:
SqlUpdate.UpdateCommand = "UPDATE ...
and
MaSqlCnx.ConnectionString = "Server=mssql02 ...
The strings in the lines above each need to be on a single line, or have a # character before the opening " character.

Related

Unable to Format Message Error when connecting to DB

I am currently working on a function that connects to a database through a connection string that includes the parameter: "Provider=OleDB.Provider". When I ran the code I get the following error:
Unable to format message, ID: 0xc0010001: Class not registered
I have also made sure the file is located on the database and the name parameter I am passing matches the name of the Database, since I got this from the msdn webstie:
"The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created."
Some of the code I have for the connection is(error happens on conn.open):
using (OleDbConnection conn = new OleDbConnection("Provider=mrOleDB.Provider.2;Persist Security Info=False;User ID=\"\";Data Source=" + data_source + ";Location=\"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" + user + "; PWD=" + password + ";Initial Catalog='" + jobnumber + "';Data Source=" + oDatabase + ";OLE DB Services=-4\";Extended Properties=\"\";Initial Catalog=" + oroot + jobnumber + "\\" + jobnumber + ".mdd;Mode=ReadWrite;MR Init MDSC=\"\";MR Init MDSC Access=2;") {
//(Theres a little more on the connection string but its adding settings for the data collection similar to the last part: MR Init mdsc)
try{
conn.Open();
}
catch(exception er)
Console.Writelin(er.message)
}
Could you please help me understand this error, or what it means? I tried looking for some solutions but was not able to find a solution that is similar to my issue. Thank you for all your help!

form refresh on 'NEXT' button click instead of going into next step

I have 1 matrimony website (ASP.NET, C#). Registration form in the website is divided into 5 steps (screenshot below).
Mostly its running okay but My main problem sometimes the form refresh on 'NEXT' button click instead of going into next step. and sometimes it auto redirect to index page of the website.
I just don't know why it's happening. I have checked the coding 100 times and I don't find any problem with the coding. Any help will be appreciated.
Mostly this happens in random steps not fixed in which step it redirect,
But I am posting a button_click event of NEXT' button reg step 2 page:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from tbl_FreeUserProfile where UserId='" + Request.QueryString["userid"].ToString() + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
ImageButton46.Enabled = false;
string userid = Request.QueryString["userid"];
DateTime last_activity = System.DateTime.Now;
int heightf = Convert.ToInt16(DropDownList30.SelectedItem.Value);
string str1 = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection cn1 = new SqlConnection(str1);
string query1 = "update tbl_FreeUserProfile set Height='" + DropDownList30.SelectedItem.Text + "',Weight='" + DropDownList31.SelectedItem.Text + "',BloodGroup='" + DropDownList32.SelectedItem.Text + "',PhysicalStatus='" + RadioButtonList7.SelectedItem.Text + "',heightf='" + heightf + "' where UserId='" + userid + "'";
SqlCommand cmd1 = new SqlCommand(query1, cn1);
cn1.Open();
cmd1.ExecuteNonQuery();
cn1.Close();
Response.Redirect("~/Registration-Details-Step-3.aspx?username=" + Request.QueryString["username"].ToString() + "&userid=" + userid);
}
Please try use this code
if(!isPostBack)
{
//Your code
}
this code allow you to
And Why you not try Panels in your design page and so in last panel you have to fire submit event this will not refresh your page in starting step only final step page is load.
hi i have 1 query regards your form if any scenario like when you fill first step and going to second step if power is off now and when next time you come in registration form is there any way we have to see already fill step in my first step and i do not need to fill first step which is filled already as before ?.

using Service Based Database in VS2010 Ultimate

I have been working on a project related to database (.mdf). I have created some windows forms in visual studio using C#. Basically these forms work together to store, update and delete data from the Service Based Database i created.
The problem is when i build the project, it builds fine, no errors. It inserts a data provided from textboxes to the datagridview too as intended. But as soon as i stop the current debugging, and then rerun it again, all the data provided previously is lost from the datagridview!!
I cant understand why this is happening. anyone please help me. Im totally new to this stuff.. a bit of guidance would be heartily appreciated.
when i had previously used MySQL for the same purpose, the updated data would be permanently stored to the database, but since i migrated from the MySQL to SQL Server's Service Based Database, i get such confusing error.
......
void loadData()
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["baikalpik_bidhut_sewaConnectionString"].ToString());
SqlCommand cmd = new SqlCommand("SELECT SNo,Customer_ID, Citizenship_No, Name, Subscription_Date, Phone_No, Location,Locality,Bulbs,Deposit,Monthly_Charge FROM customerinformation;", con);
try
{
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
DataTable dt = new DataTable();
adp.Fill(dt);
dataGridViewCustomerInformation.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
try
{
float m_chrg = Convert.ToInt64(textBoxBulbs.Text)*500;
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["baikalpik_bidhut_sewaConnectionString"].ToString());
SqlCommand cmd = new SqlCommand("INSERT INTO customerinformation(SNo,Customer_ID,Citizenship_No,Name,Subscription_Date,Location,Locality,Bulbs,Deposit,Phone_No,Monthly_Charge) values('" + textBoxSNo.Text + "','" + textBoxCustomerID.Text + "','" + textBoxCitizenshipNumber.Text + "','" + textBoxName.Text + "','" + textBoxSubscriptionDate.Text + "','" + textBoxLocation.Text + "','" + textBoxLocality.Text + "','" + textBoxBulbs.Text + "','" + textBoxDeposit.Text + "','" + textBoxPhoneNumber.Text + "','" + m_chrg + "')", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
dt = new DataTable();
dt.Load(reader);
con.Close();
dataGridViewCustomerInformation.DataSource = dt;
loadData();
MessageBox.Show("Entry Added!");
fillListbox();
textBoxSNo.Clear();
textBoxBulbs.Clear();
textBoxCitizenshipNumber.Clear();
textBoxCustomerID.Clear();
textBoxDeposit.Clear();
textBoxLocality.Clear();
textBoxLocation.Clear();
textBoxPhoneNumber.Clear();
textBoxName.Clear();
textBoxSubscriptionDate.Clear();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
If you have your MDF listed in your project files then the property Copy To Output Directory handles how your MDF file is copied to the output directory (BIN\DEBUG or BIN\RELEASE).
If this property is set to Copy Always, then when you run your program a fresh copy of your database file is copied from the project folder to the output effectively destroying every data that you have inserted, modified, deleted in the previous run of your program.
The best solution to this dilemma is to add the MDF file as a permanent database inside your current install of Sql Server and adjust your connection string. And of course set the property to Copy Never
In alternative you could set to Copy if newer. This will allow to change the database schema inside the Server Explorer and let the Visual Studio IDE copy the new structure only after you have made changes.
UPDATE BUT IMPORTANT Not related to your actual question, but your insert query is a serious problem. Do not use string concatenation to build a sql command text. Particularly if the partial text comes from user input. You could face syntax errors (if someone places a single quote inside a text box) or worst, a Sql Injection problem (see here for a funny explanation)
To find good examples of Insert search for 'parametrized query'

How to Create an Excel File in C#; Office 2007; Win 7 64bit?

Previously my C# app used this command to create an Excel file:
try
{
//SELECT INTO command
string cnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + AccfilePath +
";Persist Security Info=False";
ConnOpen(cnStr);
using (connectionToDatabase)
{
//Give the Export Table (destination) a Name
//baseTblName = dt.TableName;
//Generate the SQL string to SELECT * INTO the NEW table in destination
string selectcmd = "SELECT * INTO [Excel 12.0;Database=c:\\"+ExfilePath+"]." + tblName + " FROM " + tblName;
using (OleDbCommand createCmd = new OleDbCommand(selectcmd, connectionToDatabase))
{
createCmd.ExecuteNonQuery();
}
ConnClose();
}
}
I have moved to Win 7 64 bit and the OleDbCommand now gives me a "Failure Creating File". I have gone so far as to make the user an Administrator because I assumed it was a security issue.
There is no problem with this Oledb command. I have been fighting 64bit issues all day and assumed there was. My file path had incorrect syntax; after I fixed that it worked as expected.

Error while opening a connection to MS Access 2007 file: Cannot open the MS Office Access database engine workgroup information file

Cannot open the MS Office Access database engine workgroup information file - When I have code as posted.
What I am trying to do in my code is to create MS Access 2007 file and then set the user name and password to it from my program. What am I doing wrong here?
Error occurs here: objOleDbConnection.Open();
EDIT: I have made some changes, seems like it opens a connection but the command is incorrect.
Now problem is here:
objOleDbCommand.CommandText =
"ALTER USER " + storedAuth.UserName +
" PASSWORD [" + storedAuth.Password + "] []";
The entire code:
// Creating an object allowing me connecting to the database.
OleDbConnection objOleDbConnection = new OleDbConnection();
objOleDbConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + sfdNewFile.FileName + ";Persist Security Info=False";
// Creating command object.
OleDbCommand objOleDbCommand = new OleDbCommand();
objOleDbCommand.Connection = objOleDbConnection;
try
{
objOleDbConnection.Open();
objOleDbCommand.CommandText = "ALTER USER " +
storedAuth.UserName + " PASSWORD [" +
storedAuth.Password + "] []";
objOleDbCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
// Displaying any errors that
// might have occured.
MessageBox.Show("Error: " + ex.Message);
}
finally
{
objOleDbConnection.Close();
}
To change an Access DB password, you must it open in exclusive mode. Try adding this to your connection string ;Exclusive=1.
createMSFile.Create("Provider=Microsoft.ACE.OLEDB.12.0;Exclusive=1;Data Source=" +
sfdNewFile.FileName);
Well, the error you are getting suggests someone else is keeping the file open, which prevents the password change...
HelpNeeder, I think the problems you are experiencing should first be solved in your other question:
Error tells me I haven't close the connection, but haven't I?
Thanks!

Categories