Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Asynchronous Response to a Synchronous TCPClient Pin
jschell6-May-11 10:48
jschell6-May-11 10:48 
QuestionHow to load Arabic File name Pin
raushan_93-May-11 8:41
raushan_93-May-11 8:41 
AnswerRe: How to load Arabic File name Pin
Pete O'Hanlon3-May-11 9:02
mvePete O'Hanlon3-May-11 9:02 
QuestionC# and Power Point Pin
PDTUM3-May-11 7:55
PDTUM3-May-11 7:55 
AnswerRe: C# and Power Point Pin
Pete O'Hanlon3-May-11 9:36
mvePete O'Hanlon3-May-11 9:36 
AnswerRe: C# and Power Point Pin
PDTUM3-May-11 13:01
PDTUM3-May-11 13:01 
GeneralRe: C# and Power Point Pin
wizardzz4-May-11 10:01
wizardzz4-May-11 10:01 
QuestionConnection String problem Pin
si_693-May-11 6:01
si_693-May-11 6:01 
Hi
I am having trouble building my database connection string, i have to read the server name, db, un, and password from an INI file (dont ask)

This is no problem, but im having trouble using these values to build my connection string

currently im getting the error

A field initializer cannont reference the nonstatic field, method or property

my knowledge of C# is basic to say the least, can anyone point me in the correct diretion or help at all?

thanks

Simon

Code Below


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;

using System.Runtime.InteropServices;
namespace WebService1
{
	/// <summary>
	/// Summary description for Service1.
	/// </summary>
	public class Service1 : System.Web.Services.WebService
	{
		string con;
		string ini_path;
		string tc_server="";
		string tc_database="";
		string tc_un="";
		string tc_pwd="";
		string tc_server_str="";
		public Service1()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();
			ReadIniSettings();
			con=CreateConnectionString();
		}
		SqlConnection myConnectionCP2 = new SqlConnection(con);   


		#region Component Designer generated code
		
		//Required by the Web Services Designer 
		private IContainer components = null;
				
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion
		void ReadIniSettings()
		{
			ini_path="F:\\Web\\tr\\htdocs\\cpbl4\\";
			tc_server = IniFile.ReadValue(ini_path,"TC","Server");
			tc_database=IniFile.ReadValue(ini_path,"TC","Database");
			tc_un=IniFile.ReadValue(ini_path,"TC","UN");
			tc_pwd=IniFile.ReadValue(ini_path,"TC","Pwd");
		
		}
		string CreateConnectionString()
		{
			tc_server_str=SQLConn.CreateConnStr(tc_server,tc_un,tc_pwd,tc_database);
			return tc_server_str;
			
		}
	}
	public class IniFile
	{
		[DllImport("kernel32")]
		private static extern long WritePrivateProfileString(string section,string key, string val, string filePath);
		[DllImport("kernel32")]
		private static extern int GetPrivateProfileString(string section,string key, string def, StringBuilder retVal,int size, string filePath);
 
		public static void WriteValue(string path, string Section, string Key, string Value)
		{
			WritePrivateProfileString(Section, Key, Value, path);
		}
 
		public static string ReadValue(string path, string Section, string Key)
		{
			StringBuilder temp = new StringBuilder(255);
			int i = GetPrivateProfileString(Section, Key, "", temp, 255, path);
			return temp.ToString();
		}
	}
	public class SQLConn
	{
		//SqlConnection myConnectionCP2;
		public static string CreateConnStr(string server, string un, string pwd, string db)
		{
			string connStr = "server="+server+";max pool size = 7500;uid="+un+";pwd="+pwd+";database="+db+";Connect Timeout=200;"; 
			return connStr;
			
		}
		
       
	}
}

AnswerRe: Connection String problem Pin
Ian Shlasko3-May-11 6:17
Ian Shlasko3-May-11 6:17 
AnswerRe: Connection String problem Pin
Pete O'Hanlon3-May-11 6:18
mvePete O'Hanlon3-May-11 6:18 
AnswerRe: Connection String problem Pin
DaveAuld3-May-11 6:20
professionalDaveAuld3-May-11 6:20 
AnswerRe: Connection String problem Pin
Luc Pattyn3-May-11 6:28
sitebuilderLuc Pattyn3-May-11 6:28 
GeneralRe: Connection String problem Pin
Pete O'Hanlon3-May-11 6:44
mvePete O'Hanlon3-May-11 6:44 
GeneralRe: Connection String problem Pin
Luc Pattyn3-May-11 6:51
sitebuilderLuc Pattyn3-May-11 6:51 
Questiona try inside another Pin
Ali Al Omairi(Abu AlHassan)3-May-11 0:44
professionalAli Al Omairi(Abu AlHassan)3-May-11 0:44 
AnswerRe: a try inside another Pin
Rick van Woudenberg3-May-11 1:07
Rick van Woudenberg3-May-11 1:07 
AnswerRe: a try inside another Pin
Luc Pattyn3-May-11 1:12
sitebuilderLuc Pattyn3-May-11 1:12 
GeneralRe: a try inside another Pin
Rick van Woudenberg3-May-11 1:21
Rick van Woudenberg3-May-11 1:21 
GeneralRe: a try inside another Pin
Pete O'Hanlon3-May-11 1:44
mvePete O'Hanlon3-May-11 1:44 
GeneralRe: a try inside another Pin
Rick van Woudenberg3-May-11 1:57
Rick van Woudenberg3-May-11 1:57 
GeneralRe: a try inside another Pin
J4amieC3-May-11 3:00
J4amieC3-May-11 3:00 
GeneralRe: a try inside another Pin
Rick van Woudenberg3-May-11 4:14
Rick van Woudenberg3-May-11 4:14 
GeneralRe: a try inside another Pin
J4amieC3-May-11 4:36
J4amieC3-May-11 4:36 
GeneralRe: a try inside another Pin
BobJanova3-May-11 4:44
BobJanova3-May-11 4:44 
GeneralRe: a try inside another Pin
J4amieC3-May-11 4:50
J4amieC3-May-11 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.