怎么用相对路径连接数据库
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.Data.SqlClient;
namespace cadADO
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection coon = new SqlConnection(@"Server=.\SQLExpress;AttachDbFilename=G:\WPF\cadADO\cadADO\bin\Debug\Database1.mdf;Trusted_Connection=sspi;"))
{
coon.Open();
MessageBox.Show("连接成功");
}
}
}
}
在CAD里面用AttachDbFilename=|DataDirectory|Database1.mdf就发生错误,必须用AttachDbFilename=G:\WPF\cadADO\cadADO\bin\Debug\Database1.mdf。怎么才能使用相对路径连接数据库呢?
连接字符使用变量即可,想怎么连就怎么连接!
页:
[1]