Re: VB.NET app deployment
If using SQL Express then ComputerName\SQLExpress (this is a named instance).
Re: VB.NET app deployment
that's exactly my problem ... ComputerName is different for every computer I install the application ... it must be an environment variable that emulates the ComputerName in VB.NET
For example if my computer has ComputerName='MAKKO' and the computer I must install the application has the ComputerName='SOMETHINGELSE' on my computer the environment variable has to be MAKKO and on other computer the environment variable should be SOMETHINGELSE
Re: VB.NET app deployment
You shouldn't be using the machine name at all. This is from www.connectionstrings.com:
Quote:
Data Source=.\SQLExpress;Integrated Security=true;AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;
That is also what VS does by default when you add a SQL Server database to your project.
You can also use "(local)" instead of the dot.
Re: VB.NET app deployment
thank you jmcilhinney ...
So i should use Data Source=.\SQLExpress; if I install an SQLExpress named instance
If i decide to install the default instance I would use Data Source=.; or
Data Source=(local); ???
And another question regarding SQL SERVER instalation ... At the 4th step of instalation USE THE BUILT IN SYSTEM ACCOUNT ... Should I choose Local System ? or Local Service / Network
Re: VB.NET app deployment
If I enter myself the following code :
AppDomain.CurrentDomain.SetData("DataDirectory", "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data")
Dim sqlconn As String = "Server=.;AttachDbFilename=|DataDirectory|test.mdf;Database=test;Trusted_Connection=Yes;"
string strSQL = “select * from table1”;
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
dbBindSource.DataSource = table;
dbGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
dbGridView.ReadOnly = true;
dbGridView.DataSource = dbBindSource;
I get the result I want ...
But sometime I need to bind the tables to datagridview not from code but from designer ... And the designer creates automaticly an connection string like "Data Source=MYCOMPUTERNAME;Initial Catalog=test;Integrated Security=True"
What can I do so the designer creates an connection string like "Server=.;AttachDbFilename=|DataDirectory|test.mdf;Database=test;Trusted_Connection=Yes;"
Thx
Re: VB.NET app deployment
SQLExpress is always a named instance. You don't have a choice in that.
Re: VB.NET app deployment
I resolved the problem ...
At the SqlServerExpress instalation :
- selected the 'default' instance
- selected the 'local system'
In the code if I want to connect without designer I create myself the connection string like "Server=.;AttachDbFilename=|DataDirectory|test.mdf;Database=test;Trusted_Connection=Yes;"
If I want to connect with designer the connection strings will look like "Data Source=MYCOMPUTERNAME;Initial Catalog=test;Integrated Security=True"
and I will replace mannualy the MYCOMPUTERNAME string with '.' character
For me that worked very well