Parsi Coders
Connection String - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Software Development Programming (http://parsicoders.com/forumdisplay.php?fid=37)
+--- انجمن: C# Programming (http://parsicoders.com/forumdisplay.php?fid=55)
+--- موضوع: Connection String (/showthread.php?tid=3285)



Connection String - mahsa_18 - 07-16-2013

 سلام
با این کد میخوام  برنامه به هر سروری  از بانک اتصال پیدا کنه اما اجرا نمیشه وکانکشن استرینگ  null برمیگردونه


کد:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace CS_WebConfig
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataTable dt;

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        public string GetString()
        {
            return ConfigurationManager.AppSettings["ConnectionString"].ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(GetString());
            SqlDataAdapter sqlda = new SqlDataAdapter("select * from TableInfo", con);
            dt = new DataTable();
            sqlda.Fill(dt);
            dataGridView1.DataSource = dt;
        }
    }
}

 


RE: Connection String - Amin_Mansouri - 07-17-2013

کد:
public void CreateSqlConnection() { SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30"; myConnection.Open(); }

http://www.dreamincode.net/forums/topic/70745-connection-string-in-appconfig/