I am using a TableAdapter in a dataset in Vb.net winforms (connected to a mysql server) to allow integration of a Devexpress scheduler - I have been using this method for some time; while I know of many of the security flaws of vb.net including decompiling and packet sniffing plain text communication; I am trying to lock down security as much as I can which brings me to my current problem.
The dataset was set up to connect using the .net framework data provider for mysql which requests a Server address, username, password, and DB file - I then get the option of "saving the login credentials in the connection string" or "setting the login credentials in my programming code" for sake of time previously I saved the login credentials.
this adds a setting file (connectionstring)
server=mysqlserveraddress.com;user id=mysqluser;password=mysqlpassword;database=mysqldb;persistsecurityinfo=True
which also means these credentials are saved in plain text in the installation folder for my program
I am trying to transition to including this connectionstring in my programming code however I do not know how to approach it - for non-dataset transactions I have already declared public const in a module which includes the credentials
'database variables
Public Const dbserver As String = "mysqlserveraddress.com"
Public Const dbuser As String = "mysqluser"
Public Const dbpassw As String = "mysqlpassword"
Public Const dbfile As String = "mysqldb"
and I create the connections when needed.
How do I programmatically enter the connection string so it is not visible to the lay-person.
Are you saying that you want to to set the user id and password attributes of an existing connection string at run time? If so then you can use the appropriate connection string builder. I don't use MySQL and Connector/Net but it should look something like this:
Dim builder As New MySqlConnectionStringBuilder(partialConnectionString)
builder.UserId = userId
builder.Password = password
Dim fullConnectionString As String = builder.ConnectionString
Anyone who decompiles your code is going to see that data though. You might consider just storing the whole lot in the config file but encrypting it. For more info on that, check this out:
http://www.vbforums.com/showthread.php?532768-NET-2-0-Protected-Configuration-(Encrypting-Config-Files)
Related
I have a server in which I use this string to connect:
string Cadena = "Server=10.10.10.10;Port=3306;Database=base;Uid=usuario;Pwd=pass;default command timeout=20000;Pooling=false;";
I want to connect to my server using a public ip like this way string Cadena = "Server=11.11.11.11;Port=3306;Database=base;Uid=usuario;Pwd=pass;default command timeout=20000;Pooling=false;";
I just want to see if there are options to do it. It is not transferring data and I do not want to use a VPN but if it is the only way to do it, I will have to. So, please give me ideas, what to search or something.
We have a package on Server A which we use to load the data into different databases on different Servers. We just change the destination Connection through "SQL Server 2008 Integration Services Package Execution Utility". When the package loads the data it sends a confirmation Email with a subject of "package name and time" that data has been loaded successfully. I want to add the destination connection (Server name and database name) in the subject to make sure the data is loading into the right destination.
Any help is greatly appreciated.
The easiest way to do this would be to use a script task to load the information into a variable.
I am assuming that if you are dynamically setting your connection that you have the connection string stored as a variable.
If so you can use the SqlConnectionStringBuilder() class in .net.
var connstring = DTS.Variables["Yourvariablehere"].Value.ToString();
var builder = new SqlConnectionStringBuilder(connstring);
DTS.Variables["servervariablehere"].Value = builder.DataSource;
DTS.Variables["databasevariablehere"].Value = builder.InitialCatalog;
I have a local SQL DB and an Azure SQL DB. In my data flow I am trying to pass data from local (ole db source) to Azure (ole db destination).
I am unable to save the password for the connection string so I have parameterized the connection string of the data flow task but I seem unable to work out how to get the destination to use it?
I know this isn't best practice but I just want to prototype a few things. Is this possible?
Thanks
Double click project params and add your connection string as a parameter. Give it any name you want, select string then paste your Azure connection string that you have copied directly from you Azure portal connection string option.
This creates a project level conn string parameter.
Right click connection managers and create a new ADO.Net connection manager. This should be fairly straightforward.
Once completed, select this connection manager and add an expression to it from the property window:
In the Property Expression Editor: (1) Select a property called ConnectionString. (2) Select the elipsis beside expression. From the pop up open the project parameters in the left hand area and you will see the connection parameter you created earlier. Drag this into the expression text area. Evaluate the expression to check it works.
Click OK
You should now be able to use this as an Azure connection without getting any errors
I've an interesting problem. One of my database related code works good on local machine. But it doesn't return anything from when published on the third party web server.
Following is the code snippet :
Public Function getUserAuthDataWithUserId(ByRef Connection As MySqlConnection,
ByVal UserId As String
) As DataTable
Dim cmd As String
cmd = "select * from tbl_md_userauth where tf_userid = '" + UserId + "' "
getUserAuthDataWithUserId = ExecuteSQL(Connection, cmd)
End Function
And the ExecuteSQL function is :
Public Function ExecuteSQL(ByRef Connection As MySqlConnection,
ByVal SQLStatement As String
) As DataTable
Dim ds As New DataSet
Dim da As New MySqlDataAdapter
Try
da = New MySqlDataAdapter(SQLStatement, Connection)
da.Fill(ds, "tbl_Return")
ExecuteSQL = ds.Tables("tbl_Return")
Catch ex As Exception
msgbox ("exception !")
End Try
End Function
Be assured that :
The database table has correct data. And the code works correctly when connecting from local machine to remote desktop.
The code works correctly when using local IIS and local database.
I've also tried republishing the code twice or thrice.
Helpdesk of web server says there is no problem with their server.
Any clue on what is wrong ?
It appears that you are swallowing your exceptions. The code appears to use a msgbox to display the error, but that will appear on the server under a hidden profile and not be sent to the browser for display. You need some other way of displaying or logging the error that works in a web environment.
That being said, are you able to get any connections to the database and just this method is failing, or are all of your database requests failing? I suspect that you are using integrated authentication in your database configuration, but the same user doesn't work on the server because IIS is running as a different user in the app pool. Try changing your development environment to point to your database on the server and see if you get any errors that way. If you are using a hosting environment, I recommend setting up a named user in your database and using that in your connection string rather than using integrated authentication.
Ultimately, it found to be a server side problem. The Helpdesk fixed it. I am yet to know what precisely they have fixed. I'll problably post it over here as soon as I hear from them.
Thanks to all of you guys who've contributed.
My CodeIgniter app on Google App Engine is not able to connect to my database on Google Cloud SQL. I tried so many things.
My site loads when I leave database username, password & database name empty but, pages that have database calls show an error. It says that no database was selected.
I noticed that my database was not created and created a new database and a user with all privileges. I entered this details in my app and now, it doesn't even connect to the database server. No pages serve.
When I remove only the username & password fields in database.php, it connects to the database server but, doesn't connect to the database.
I checked the mysql database for users and my user has all privileges. I checked all spellings and it is correct. The app is working locally. HOW I CAN FIX THIS? i just can't get it to connect.
Out of the box CodeIgniter will not connect to a Google Cloud SQL instance, modifications to the CI database driver files are required, this is because CI expects that it’s choices are either to connect to localhost or to a remote tcpip host, the developers never anticipated that anybody would want to connect directly to a socket.
I chose to use the Mysqli driver instead of Mysql for performance reasons and here is how I did it:
Step 1) Edit the codeigniter/system/database/drivers/mysqli/mysqli_driver.php file and replace the db_connect function with the following code:
function db_connect()
{
if(isset($this->socket)){
return mysqli_connect(null, $this->username, null, $this->database, null, $this->socket);
}
elseif ($this->port != ”)
{
return mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port);
}
else
{
return mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
}
}
Step 2) Alter your application’s config/database.php (or wherver you want to declare your database settings) - Depending on your application you may choose to add “database” to the autoload array in the yourapp/config/autoload.php or you may choose to manually call the load->database() function. This assumes your application name is “myappname”. Replace APPENGINE-ID and DATABASE-INSTANCE-ID and YOUR_DATABASE_NAME appropriately.
$db[‘myappname’][‘hostname’] = ‘localhost’;
$db[‘myappname’][‘username’] = ‘root’;
$db[‘myappname’][‘password’] = null;
$db[‘myappname’][‘database’] = ‘YOUR_DATABASE_NAME’;
$db[‘myappname’][‘dbdriver’] = ‘mysqli’;
$db[‘myappname’][‘pconnect’] = FALSE;
$db[‘myappname’][‘dbprefix’] = ‘’;
$db[‘myappname’][‘swap_pre’] = ‘’;
$db[‘myappname’][‘db_debug’] = FALSE;
$db[‘myappname’][‘cache_on’] = FALSE;
$db[‘myappname’][‘autoinit’] = FALSE;
$db[‘myappname’][‘char_set’] = ‘utf8’;
$db[‘myappname’][‘dbcollat’] = ‘utf8_general_ci’;
$db[‘myappname’][‘cachedir’] = ”;
$db[‘myappname’][‘socket’] = ‘/cloudsql/APPENGINE-ID:DATABASE-INSTANCE-ID’;
Viola, your CodeIgniter application should now be able to connect and talk to your Google Cloud MySQL database!
Now if you want to get really fancy and enable the database caching, either make alterations to the CI code to use memcache (fastest) or Google Cloud Storage (more guaranteed persistance) but I won’t cover that in this blog…
Answer courtesy of http://arlogilbert.com/post/67855755252/how-to-connect-a-codeigniter-project-to-google-cloud
Have you authorized your appengine app for access to the Cloud SQL instance? Go to the access control panel on the console for the instance (at https://cloud.google.com/console#/project/{project name}/sql/instances/{instance name}/access-control). Look for authorized app engine applications.
Otherwise, if you're connecting to the instance successfully, you'll have to choose the database from your code or configuration (depending on the app). For example, from the "running wordpress" guide (https://developers.google.com/appengine/articles/wordpress) you have to define DB_NAME. If you're handling the connections in your own code you'll need to use mysql_select_db.
From skimming the codeigniter docs, it looks like you need something like:
$config['database'] = "mydatabase";
I'm not familiar with this framework though, so check the docs yourself (http://ellislab.com/codeigniter/user-guide/database/configuration.html).