i am using visual studio 2013 and sql server 2012 . i create a wpf form project at c# which include add update delete features and database is made in sql server 2012 my project is working 100% . so after i get complete my project with database i try to make a setup and deployment of my project and its all done perfectly and my my setup of project run with all features which i put on it but when i run my application on other fresh pc where no visual studio and sql server 2012 installed its run but just showing windows form add update delete not working and its give me error that database is not connected ....then i search so many places then i found how to add database mdf file during project and deployment of project i just deatached my database from sql server then add file into setupdeploy of my project and also change the string of app.config and C# code file but its still not working and show data base not conected error can plz any buddy give me some detailed guide line or referenece that how can i make it possible
below is my app.config which work fine when i dont deatach database from sql server dont add mdf file to setup
<connectionStrings> <add name="WpfApplication2.Properties.Settings.testingConnectionString" connectionString="Data Source=EMIII-PC;Initial Catalog=testing;Integrated Security=True" providerName=".NET Framework Data Provider for SQL Server" /> </connectionStrings>
this is my app.config after changes
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> </configSections> <connectionStrings> <add name="WpfApplicaion2" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\testing.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>
this is my C# Code connection string after changes
public void BindMyData() { string dbconnection = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\testing.mdf;Integrated Security=True;User Instance=True"); SqlConnection conn = new SqlConnection(dbconnection); try { conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * from Custom", conn); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); myDataGrid.ItemsSource = ds.Tables[0].DefaultView; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } finally { conn.Close(); } } private void Window_Loaded(object sender, RoutedEventArgs e) { BindMyData(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)