Mike Eghtebas
asked on
Modify ADO connection string...
In a simple drag and drop application, I have:
connectionString="Data Source=MIKE-VAIO;Initial Catalog=WSCGSoftware;Integ rated Security=True"
connecting to a database (WSCGSoftware) in SQL Server 2012 Enterprise. I used "Add New Data Source" wizard to do this.
Question: How can I modify this connection string to the same database at "C:\TestFolder\WSCGSoftwar e.mdf" on the same computer?
This application will be tested in another computer later with "C:\TestFolder\WSCGSoftwar e.mdf" on it, but there will be no SQL Server installed on it.
If this is not possible, what if the second computer had SLQExpress installed on it.
Idealy, path "C:\TestFolder\" should be the root directory of the project itself. Some comment on it will be appreciated.
Thank you.
connectionString="Data Source=MIKE-VAIO;Initial Catalog=WSCGSoftware;Integ
connecting to a database (WSCGSoftware) in SQL Server 2012 Enterprise. I used "Add New Data Source" wizard to do this.
Question: How can I modify this connection string to the same database at "C:\TestFolder\WSCGSoftwar
This application will be tested in another computer later with "C:\TestFolder\WSCGSoftwar
If this is not possible, what if the second computer had SLQExpress installed on it.
Idealy, path "C:\TestFolder\" should be the root directory of the project itself. Some comment on it will be appreciated.
Thank you.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Test_A.My.MySettings.WSCGSoftwareConnectionString"
connectionString="Data Source=MIKE-VAIO;Initial Catalog=WSCGSoftware;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>
Since the connection string is to connect to the SQL Server, not the file, I don't see how you could possibly do that. You SQL statements and driver are not going to work directly on the file. They need the SQL Server to operate properly.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
DaveBaldwin,
re:> to connect to the SQL Server, not the file,
The attached image shows Option 1 (connecting to SQL Server) and Option 2 (connecting to database file). Having said this, I can see how it still all the drivers etc. that comes with SQL Server will be used with option 2.
So, then as stated in the original question: "...what if the second computer had SLQExpress installed on it..." then how would you modify the connection string in order to be working with "C:\TestFolder\WSCGSoftwar e.mdf" where WSCGSoftware may or may not present in the SQL installed.
TheAvenger,
re:> SQL Server will know where the database is because it is attached to it.
There might be could of instances of SQL Server with the database with the same name but with different data + plus one in C:\TestFolder again with different data. In response to this part please consider Option 1 and Option 2 on the attached image.
Also see:
https://www.experts-exchange.com/questions/28227481/Failed-to-generate-a-user-instance-of-SQL-Server.html
Data Source=.\SQLEXPRESS;Attach DbFilename ="C:\Users \Mike\Docu ments\__sm c\_CS 32 ADO\WSCGSoftwareDatabase\W SCGSoftwar e.mdf";Int egrated Security=True;Connect Timeout=30;User Instance=True
This type of connection is what I am expecting from the experts.
Thank you,
Mike
ChangeDataSource.png
re:> to connect to the SQL Server, not the file,
The attached image shows Option 1 (connecting to SQL Server) and Option 2 (connecting to database file). Having said this, I can see how it still all the drivers etc. that comes with SQL Server will be used with option 2.
So, then as stated in the original question: "...what if the second computer had SLQExpress installed on it..." then how would you modify the connection string in order to be working with "C:\TestFolder\WSCGSoftwar
TheAvenger,
re:> SQL Server will know where the database is because it is attached to it.
There might be could of instances of SQL Server with the database with the same name but with different data + plus one in C:\TestFolder again with different data. In response to this part please consider Option 1 and Option 2 on the attached image.
Also see:
https://www.experts-exchange.com/questions/28227481/Failed-to-generate-a-user-instance-of-SQL-Server.html
Data Source=.\SQLEXPRESS;Attach
This type of connection is what I am expecting from the experts.
Thank you,
Mike
ChangeDataSource.png
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Sorry, this is valid one:
I have generated this on a yet third computer with SQl Express on it and it works.
So, basically, I want have some conversation about it I can get more education about it.
The problem is this:
I have SQL Server Enterprise. I develop this simple application easily. Butthe other computer (the third computer has SQL Express).
1. I do develop with database in SQL Server 2012.
2. Give to someone else who has only SQL Express.
3. In creating the data connection we have agreed to use Option 2 (in the above image). This way, the database travels with the project and it doesn't depend on the database in their SQL Server.
So, I want to develop in SQL Server 2012. When done, modify the connection string and give it to the other person to look at the application with my data included with my app.
Alternatively, you can supply answer to the link given before to my other question this way, I don't have to look for work around like this.
Thanks,
Mike
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="TestB.My.MySettings.WSCGSoftwareConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\WSCGSoftware.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>
I have generated this on a yet third computer with SQl Express on it and it works.
So, basically, I want have some conversation about it I can get more education about it.
The problem is this:
I have SQL Server Enterprise. I develop this simple application easily. Butthe other computer (the third computer has SQL Express).
1. I do develop with database in SQL Server 2012.
2. Give to someone else who has only SQL Express.
3. In creating the data connection we have agreed to use Option 2 (in the above image). This way, the database travels with the project and it doesn't depend on the database in their SQL Server.
So, I want to develop in SQL Server 2012. When done, modify the connection string and give it to the other person to look at the application with my data included with my app.
Alternatively, you can supply answer to the link given before to my other question this way, I don't have to look for work around like this.
Thanks,
Mike
ASKER
Dave,
re:> There isn't any case that uses a file without an SQL Server.
I never said there is. I assumed there maybe hence the question because I was not sure about it and then stated if this is not possible then...
Bottom line is:
re:> There isn't any case that uses a file without an SQL Server.
I never said there is. I assumed there maybe hence the question because I was not sure about it and then stated if this is not possible then...
Bottom line is:
Option1 :
<connectionStrings>
<add name="Test_A.My.MySettings.WSCGSoftwareConnectionString"
connectionString="Data Source=MIKE-VAIO;Initial Catalog=WSCGSoftware;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
To, Option 2:
<connectionStrings>
<add name="TestB.My.MySettings.WSCGSoftwareConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\WSCGSoftware.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
You said "but there will be no SQL Server installed on it."
ASKER
Sorry Dave,
I am not blessed with English as my first language, I probably have not described properly.
When I wrote: "If this is not possible, what if the second computer had SLQExpress installed on it." I meant to say if lack SQL Server installation was not an option, lets proceed with assumption that SQL Express is present.
Update: Looking at the connection string in my last comment, I think I probably have answered my question partially, if you agree. I can change the connection string but as to manually copying and pasting the database from SQL Server .../DATA/ folder to the project root folder I am not sure but I can test it and post it here.
I am not blessed with English as my first language, I probably have not described properly.
When I wrote: "If this is not possible, what if the second computer had SLQExpress installed on it." I meant to say if lack SQL Server installation was not an option, lets proceed with assumption that SQL Express is present.
Update: Looking at the connection string in my last comment, I think I probably have answered my question partially, if you agree. I can change the connection string but as to manually copying and pasting the database from SQL Server .../DATA/ folder to the project root folder I am not sure but I can test it and post it here.
To be clear, you can not actually use Only the file but you can ask SQL Server or SQLExpress to attach that file and use it. As for the actual file location, you just have to get the details right. 'mdf' files do not have to be in the standard 'data' directory, I have several that are not that work fine. I'm not sure but I think you need to 'un-attach' the database to properly copy it. Maybe you will want to keep a 'reference' copy that is not currently attached so you could copy it and attach it on the target system.
@Dave: The right term is "Detach". There is a command when you right click on the database. Also you can see which files are in use by the database by right clicking and going to the different options that have the name "file" in them.
The database files can be in any folder that is accessible for the SQL Server user. This means the user has to have rights to read and write to the files.
If you want to make a copy of the database or move it to another server, the options are to detach it (a bit bad because it might mess up some security roles when attaching again) or the better option stop the SQL Server service, copy the files, start the SQL Server service. Works 100%
The database files can be in any folder that is accessible for the SQL Server user. This means the user has to have rights to read and write to the files.
If you want to make a copy of the database or move it to another server, the options are to detach it (a bit bad because it might mess up some security roles when attaching again) or the better option stop the SQL Server service, copy the files, start the SQL Server service. Works 100%
ASKER
Thank you very much for the info. You are right on every point made. After comparing the content of project folder, I see that it is not easily possible to manually copy and paste the files. But at least I know what wouldn't work.
Mike
Mike
ASKER
TheAvenger,
Thanks for the good comments.
Mike
Thanks for the good comments.
Mike