Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can I set the database password using an XML or text file?
Posted
Updated 15-Jul-11 23:07pm
v2
Comments
Chiranthaka Sampath 19-Jul-11 11:04am    
I have found this C# 2005 code but I do not know how to use it with vb 2005

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.OracleClient;
using System.Net.Mail;

namespace POs_Rev
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
DataSet ipg_duplicate = new DataSet();
using (OracleConnection cnn = new OracleConnection(new StreamReader(Application.StartupPath + @"\ConString.txt").ReadLine()))
{
using (OracleCommand cmd = new OracleCommand())
{
cmd.CommandText = "select a.i002_number Credit_Card_Number , a.amount Amount , b.i038_auth_id Auth_ID , b.i042_merch_id Merchant_ID ,mc.CNAME Merchant_Name,count(*) No_of_txns_on_Same_Auth_ID from primentb.ctransactions a,primentb.cisotrxns b,primentb.merchantx mc where a.serno = b.serno and a.FRAGMENTINDICATOR = b.FRAGMENTINDICATOR and b.i043a_merch_name like '%IPG%'and a.postdate > trunc(sysdate -7) and b.i042_merch_id = mc.numberx group by a.i002_number , a.amount , b.i038_auth_id , b.i042_merch_id,mc.CNAME having count(*)>1";
cmd.CommandType = CommandType.Text;
cmd.Connection = cnn;

if (cnn.State != ConnectionState.Open)
cnn.Open();
OracleDataAdapter adaptor = new OracleDataAdapter();
adaptor.SelectCommand = cmd;

adaptor.Fill(ipg_duplicate);
cnn.Close();

if (ipg_duplicate.Tables[0].Rows.Count > 0)
{
//System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\Duplicate_ipg.txt",false);

//foreach (DataRow row in ipg_duplicate.Tables[0].Rows)
//{
// file.WriteLine("========== Transaction =================");
// file.WriteLine(" ");
// file.WriteLine("i002_number" + ":" + "=" + " " + row["i002_number"].ToString());
// file.WriteLine("amount" + ":" + "=" + " " + row["amount"].ToString());
// file.WriteLine("i038_auth_id" + ":" + "=" + " " + row["i038_auth_id"].ToString());
// file.WriteLine("i042_merch_id" + ":" + "=" + " " + row["i042_merch_id"].ToString());
// file.WriteLine("count" + ":" + "=" + " " + row["count"].ToString());
// file.WriteLine(" ");
// file.WriteLine(" End Of Transaction ");
// file.WriteLine("========== **************** ==========");
// file.WriteLine(" ");
// file.WriteLine(" ");

//}
//file.Close();

ipg_duplicate.Tables[0].TableName = "DuplicatePmtEnty";
ipg_duplicate.WriteXml(@"D:\XML1\ipg.xml");

using (MailMessage mesage = new MailMessage())
{
mesage.From = new MailAddress("Payment.Master@nationstrust.com", "NTB Report Master");
mesage.To.Add(new MailAddress("echannels@nationstrust.com"));
mesage.Subject = "Duplicate IPG Txns From " + System.DateTime.Now.AddDays(-8).ToString("dd-MMM-yy") + " To " + System.DateTime.Now.AddDays(-1).ToString("dd-MMM-yy");
mesage.Body = "Pls find the attached duplicate IPG transaction file,Cross check with the CTL-PRIME before sending for reversals" +
"\r\n" + " " + "\r\n" + "--- This is a system generated email ,Plase do not reply ---";
Attachment attachFile = new Attachment("D:\\XML1\\ipg.xml");
mesage.Attachments.Add(attachFile);
new SmtpClient("192.168.100.244", 25).Send(mesage);
}
}
else
{

using (MailMessage mesage = new MailMessage())
{
mesage.From = new MailAddress("Payment.Master@nationstrust.com", "NTB Report Master");
mesage.To.Add(new MailAddress("echannels@nationstrust.com"));
mesage.Subject = "Duplicate IPG Txns - " + System.DateTime.Now.AddDays(-1).ToString("dd-MMM-yy");
mesage.Body = "There are no duplicate IPG txns on :" + System.DateTime.Now.AddDays(-1).ToString("dd-MMM-yy") +
"\r\n" + " " + "\r\n" + "--- This is a system generated email ,Plase do not reply ---";
new SmtpClient("192.168.100.244", 25).Send(mesage);
}

}



}
}

}
catch (Exception ex)
{
#region
try
{
using (MailMessage mesage = new MailMessage())
{
mesage.From = new MailAddress("Payment.Master@nationstrust.com", "NTB Report Master");
mesage.To.Add(new MailAddress("echannels@nationstrust.com"));
mesage.S

You mean the user Login?

SQL
ALTER LOGIN Account_Name WITH
PASSWORD = @newPassword
OLD_PASSWORD = @oldPassword;
 
Share this answer
 
Comments
Chiranthaka Sampath 17-Jul-11 20:53pm    
No not the user log in. Let me explain it again. When we set a password to the database it should declare at the Connection String. But if we change the password we have to re compile the whole program by adding that new password. But if we set the password separately in a XML or text file we only have to change the password at there and do not have to recompile the whole program.

How can I able to do that!
Chiranthaka Sampath 18-Jul-11 7:21am    
Hello am I alone in here?
No one giving solutions to me so sad!
 
Share this answer
 
Comments
Maciej Los 28-Jul-11 14:49pm    
Use "Improve question" to change your question! Don't be rude!
Why not create 2 settings in the app.configuration file?

1 setting for the connection string
1 for password

Reconstruct these in your application at runtime?
 
Share this answer
 
No I want to store the username and password externally from the solution and it should be in a text or XML file.So that I will be able to change the username and password easily without recompiling the solution.
 
Share this answer
 
Comments
Maciej Los 28-Jul-11 14:47pm    
Use "Improve question" to change your question!
Don't you guys know how to connect an XML file to vb 2005?
 
Share this answer
 
Comments
Maciej Los 28-Jul-11 14:47pm    
Use "Improve question" to change your question!
Maciej Los 28-Jul-11 14:48pm    
Use "Improve question" to change your question!
You can read xml files using many methods, i.e.:
DataTable.ReadXml[^]
XML File Parsing in VB.NET[^]
Reading XML Files in VB.NET[^]

Always use google and behave yourself, gentle!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900