|
i do copy paste and add through existing item both not work if i add existing item, its says path\database.mdf can not be opened because it is version 852, this server support version 655 and earlier.
|
|
|
|
|
So ... you are trying to persuade an earlier - lots earlier - version of software to open a datafile created by a later version and it is saying "I don't understand that data file, it's way too advanced for me"
Does any of that give you a clue as to why this is causing a problem?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
yes i use visual studio 2010, and Mssql server 2016.
|
|
|
|
|
And MsSql 2016 generates data in version 852 format, the server you are opening it on uses version 655 and earlier. So it looks at it, says "I don't know what the future holds, I'm not touching it, I'll damage something" and reports an error.
At a guess, you trying to open a 2016 file on SQL 2008 ... that's like trying to fit a 2019 Intel processor into a 2008 motherboard!
This is why you don't just ship an MDF file around: you create your DB on the "new" server using CREATE DATABASE, CREATE TABLE, and such like statements when you install your application.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have a c++ application code which I have attached below . I want to call the dll functions from a c# application . I am stuck with function pointers and explicit calling of function pointers using getProcAdress(). Please suggest a way
#include <cstdlib>
#include <iostream>
#include <windows.h>
//#include "ess_c.h"
/* Define functions prototype */
typedef unsigned long long(__stdcall *init)(int);
typedef int(__stdcall *serial)(unsigned long long, unsigned short *, unsigned short *);
typedef int(__stdcall *close)(unsigned long long);
typedef int(__stdcall *read2SWITCH)(unsigned long long handle, unsigned char two_switch, unsigned char * presence,
unsigned char * type, unsigned char * model, unsigned char * soft_vers, unsigned char * status, unsigned char * origin);
typedef int(__stdcall *readROTSWITCH)(unsigned long long handle, unsigned char rot_switch, unsigned char * presence,
unsigned char * type, unsigned char * model, unsigned char * soft_vers, unsigned char * err_code,
unsigned char * processing, unsigned char * position);
typedef int(__stdcall *setROTSWITCH)(unsigned long long handle, unsigned char rot_switch, unsigned char position, unsigned char direction);
int main(int argc, char *argv[])
{
/* Load DLL into memory */
HINSTANCE ProcDLL_ESS;
#ifdef _WIN64
ProcDLL_ESS = LoadLibrary(TEXT("ess_c_64.dll"));
#else
ProcDLL_ESS = LoadLibrary(TEXT("ess_c_32.dll"));
#endif
/* Declare pointers on dll functions */
init dll_init;
serial dll_serial;
close dll_close;
read2SWITCH dll_read2SWITCH;
readROTSWITCH dll_readROTSWITCH;
setROTSWITCH dll_setROTSWITCH;
/* Link dll pointers with functions prototype */
dll_init = (init)GetProcAddress(ProcDLL_ESS, "ess_initialization");
dll_serial = (serial)GetProcAddress(ProcDLL_ESS, "ess_get_serial");
dll_close = (close)GetProcAddress(ProcDLL_ESS, "ess_close");
dll_read2SWITCH = (read2SWITCH)GetProcAddress(ProcDLL_ESS, "ess_get_data_two_switch");
dll_readROTSWITCH = (readROTSWITCH)GetProcAddress(ProcDLL_ESS, "ess_get_data_rot_switch");
dll_setROTSWITCH = (setROTSWITCH)GetProcAddress(ProcDLL_ESS, "ess_set_rot_switch");
/* Define variables used for ESS */
unsigned long long essHandle = 0;
unsigned short Serial = 0;
unsigned short Version = 0;
unsigned char position = 0;
unsigned char two_switch = 0; // 2-SWITCH position (0 is the 1st on the SWITCHBOARD)
unsigned char rot_switch = 0; // ROT-SWITCH position (0 is the 1st, position 'A')
/* SWITCH variables definition used by the shared library */
unsigned char Presence;
unsigned char Type;
unsigned char Model;
unsigned char Software_Version;
unsigned char Status;
unsigned char Origin;
unsigned char Err_code;
unsigned char Processing;
unsigned char Position;
unsigned int localCount = 0;
if (ProcDLL_ESS != NULL) { // If dll loaded
std::cout << "ESS dll loaded" << std::endl;
/* Initialize device */
if (dll_init != NULL) { // Check if function was properly linked to the dll file
/* Initialize the first SWITCHBOARD in Windows enumeration list */
essHandle = dll_init(0);
std::cout << "ESS session initialized" << std::endl;
}
/* Read device serial number */
if (dll_serial != NULL) {
/*Get the serial number of the SWITCHBOARD*/
dll_serial(essHandle, &Serial, &Version);
std::cout << "SWITCH BOARD SN: " << Serial << std::endl;
}
/* Get status of the 2-SWITCH (N°1 on the board) */
if (dll_read2SWITCH != NULL){
dll_read2SWITCH(essHandle, two_switch, &Presence, &Type, &Model, &Software_Version, &Status, &Origin);
if ((Presence == 1) && (Type == 1)){ // If 2-SWITCH detected
std::cout << std::endl << "2-SWITCH detected." << std::endl;
std::cout << "Model (1 if 2-SWITCH): " << int(Model) << std::endl; // Display model
std::cout << "Software version: " << int(Software_Version) << std::endl; // Display software version
if (Status == 1){ // Display 2-SWITCH status
std::cout << "Switch is ON." << std::endl;
}
else{ std::cout << "Switch is OFF." << std::endl; }
}
else{ std::cout << "No 2-SWITCH found on 1st position." << std::endl; }
}
/* Get status of the ROT-SWITCH (N°A on the board) */
if (dll_readROTSWITCH != NULL){
dll_readROTSWITCH(essHandle, rot_switch, &Presence, &Type, &Model, &Software_Version, &Err_code, &Processing, &Position);
if ((Presence == 1) && (Type == 0)){ // If SWITCH detected
std::cout << std::endl << "ROT-SWITCH detected." << std::endl;
std::cout << "Model (1: M-SWITCH; 3: L-SWITCH): " << int(Model) << std::endl; // Display model
std::cout << "Software version: " << int(Software_Version) << std::endl; // Display software version
std::cout << "Switch position: " << int(Position) << std::endl; // Display ROT-SWITCH position
/* Change ROT-SWITCH position */
if (Position == 0){ // SWITCH changes from position 1 to 0 or from 0 to 1
dll_setROTSWITCH(essHandle, rot_switch, 1, 0);
}
else{
dll_setROTSWITCH(essHandle, rot_switch, 0, 0);
}
std::cout << "ROT-SWITCH position changed!" << std::endl;
/* Wait for processing flag to be active */
do {
dll_readROTSWITCH(essHandle, rot_switch, &Presence, &Type, &Model, &Software_Version, &Err_code, &Processing, &Position);
Sleep(100);
} while (Processing != 1);
Sleep(100);
/* Wait for processing flag to be down */
do{
dll_readROTSWITCH(essHandle, rot_switch, &Presence, &Type, &Model, &Software_Version, &Err_code, &Processing, &Position);
Sleep(100);
} while (Processing == 1);
Sleep(100);
// Read new position after change
dll_readROTSWITCH(essHandle, rot_switch, &Presence, &Type, &Model, &Software_Version, &Err_code, &Processing, &Position);
std::cout << "New Switch position: " << int(Position) << std::endl; // Display ROT-SWITCH position
}
else{ std::cout << "No ROT-SWITCH found on position 'A'." << std::endl; }
}
/* Close ESS session */
if (dll_close != NULL) {
dll_close(essHandle);
std::cout << std::endl << "ESS session closed" << std::endl;
}
}
/* Release the DLL */
FreeLibrary(ProcDLL_ESS);
std::cout << "ESS dll unloaded" << std::endl;
/* Exit application */
system("PAUSE");
return EXIT_SUCCESS;
}
modified 12-Nov-19 1:57am.
|
|
|
|
|
|
I referred the platform invoke concept.
The problem is with the function pointers declaration of the above mentioned code in c# and calling them in main function
|
|
|
|
|
Using P/Invoke is the only simple method of accessing a C-style library from C#. You need to check the documentation for the various functions to see how to implement the calls.
|
|
|
|
|
Hiya all, I'm trying to get my code to allow me to login with details from a .csv file. The code is not splitting correctly and therefore says the user and pass is incorrect. I'm wanting it to open a second form.
Any suggestions? Here's the code..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace --------
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Label1_Click(object sender, EventArgs e)
{
}
private void BtnLogin_Click(object sender, EventArgs e)
{
string Username = txtUsername.Text;
string Password = txtPassword.Text;
bool Found = false;
string FilePath = "Login.csv";
StreamReader fileReader = new StreamReader(FilePath);
String[] details = File.ReadAllLines(FilePath);
String[] splitted;
foreach (string line in details)
{
splitted = line.Split(',');
if (details[0] == Username && details[1] == Password)
{
Found = true;
}
}
if (Found == true)
{
Form2 Form2 = new Form2();
Form2.Show();
this.Hide();
}
else
{
AutoClosingMessageBox.Show("Incorrect Login Details Entered", "Error:", 5000);
}
}
}
}
public class AutoClosingMessageBox
{
System.Threading.Timer _timeoutTimer;
string _caption;
AutoClosingMessageBox(string text, string caption, int timeout)
{
_caption = caption;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
using (_timeoutTimer)
MessageBox.Show(text, caption);
}
public static void Show(string text, string caption, int timeout)
{
new AutoClosingMessageBox(text, caption, timeout);
}
void OnTimerElapsed(object state)
{
IntPtr mbWnd = FindWindow("#32770", _caption);
if (mbWnd != IntPtr.Zero)
SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
_timeoutTimer.Dispose();
}
const int WM_CLOSE = 0x0010;
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
}
|
|
|
|
|
What can you see when you debug the part where you split the string?
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Storing passwords in clear text in a text file is such a bad idea. You might just as well throw this code away, since anyone can break into a system with no security.
|
|
|
|
|
Snap!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Well, sort of. Your answer was far more comprehensive. And I continue to be amazed at how many "developers" are still routinely doing this.
|
|
|
|
|
Couple of things:
1) CSV doesn't necessarily have to be just "separated by commas" - CSV data can also contain double quotes and newlines:
"Mike Jones", "2, Brain Drive, Fullchester"
Instead of just using Split, try this: A Fast CSV Reader[^] - it does all the donkey work for you!
2) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
And remember: if you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Nice namespace
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
How to save a document like MS word and picture on c# and print
|
|
|
|
|
There are a number of options, but it all depends on what you are doing. Please provide more details of exactly where you are stuck in your code.
|
|
|
|
|
That's not a simp0le question to answer - there are a whole bunch of ways to do that.
Perhaps if you look at the simplest method: RichTextBox Class (System.Windows.Forms) | Microsoft Docs[^] and see if that fits your needs. If it doesn't, then at least you have a starting point to list the features you do need, and guide your search for a more complete method.
But we can't just say "do this" to such a generic question!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If this is your first, you start with Rtf and the RichTextControl.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi forum members,
I am very new beginner in programming. I am trying to develop a window application form database project. The database has four different user roles that log in at the UserLogin form (i.e. Admin, Accountant, HR and ReadOnly).
When any of the users logs in, they are all redirected to a Dashboard with four link buttons named; Admin, Accountant, HR and ReadOnly; that open to the individual's access pages. Now, with the exception of the Admin, I want all the other roles buttons on the Dashboard disabled except the button of the role user who logged in.
I will appreciate if someone could assist me modify my code in order to achieve the expected success.
Below is a section of my login code:-
<pre> private void loginButton_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
SqlCommand command = new SqlCommand();
con.Open();
string userText = userTextBox.Text;
string passText = pwdTextBox.Text;
SqlCommand cmd = new SqlCommand("select role from UsersLogin where UserName='" + userTextBox.Text + "'and Password='" + pwdTextBox.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Welcome to the Dashboard");
this.Hide();
dashboard.Show();
cmd = new SqlCommand("SELECT Role from UsersLogin where Username=@Username", con);
cmd.Parameters.AddWithValue("@Username", userText);
string role = cmd.ExecuteScalar().ToString();
MessageBox.Show("Welcome " + role);
con.Close();
}
else
{
MessageBox.Show("Access Denied!!");
Application.Exit();
}
con.Close();
}
modified 9-Nov-19 4:16am.
|
|
|
|
|
I know you are a student, but ... don't do it like that!
Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
You know how to use them, so ignoring that for your login page is just plain stupid, as
1) Anyone can log in as any user without needing a password.
2) Anyone can delete your DB without even having a valid username!
To add to that, a cardinal sin: Storing passwords in plain text[^]
Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
And remember: if you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Users do not need to know what other roles exist on the system, especially users with no special rights. When a user logs in you should find their role details in the database. From that information you can automatically take them to the page which is appropriate to their role; there is no need for the four buttons.
modified 9-Nov-19 5:33am.
|
|
|
|
|
Except if the User has multiple roles!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Except you code that in the DB as a bitfield to allow for multiple roles: role AND (HR OR Accountant) != 0
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That is easy to manage by the use of permission flags; as is evident here on CodeProject.
|
|
|
|
|